My app closes right after I allow permissions for external storage and audio and resumes from there when I open it next time. It is happening in an actual(real) device but works perfectly fine on the AVD. I have used dexter library for taking permissions.
Here is the code-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView=findViewById(R.id.listView);
runtimePermission();
}
//method to take the permission from the user to access external storage; if granted run displaySongs() method
public void runtimePermission()
{
Dexter.withContext(this).withPermissions(Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.RECORD_AUDIO).withListener(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport multiplePermissionsReport) {
displaySongs();
}
@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> list, PermissionToken permissionToken) {
permissionToken.continuePermissionRequest();
}
}).check();
}
Here are the permissions in Manifest
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
The closing of the app after giving runtime permissions after installing it on a device for the first time gives an annoying experience.Hope anyone could help me with this.