Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

requestPermission() doesn't fully recreate the activity stack

I have activity A that launches activity B. This activity then requests READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE. On Android 6.0, this brings up the permission dialog (which immediately destroys activity B as soon as the dialog pops up). However, whatever the user picks, the system will then return to activity A.

Requesting other permissions works fine in other places, but I suppose the external storage permissions are some of those that, as the docs warn, "require a restart of the application", and "the system will recreate the activity stack".

My problem is that activity B is never recreated, let alone onRequestPermissionsResult being called. I would have thought "recreating the activity stack" involves launching activity B again, and ideally onRequestPermissionResult being called on it. How am I supposed to handle this?

like image 335
EboMike Avatar asked Oct 26 '15 06:10

EboMike


1 Answers

which immediately destroys activity B as soon as the dialog pops up

That sounds weird to me. Activity B should be paused (and maybe stopped) at that point, but not destroyed. Are you sure you're not calling finish() or using some property like noHistory?

You may be able to find some clues as to why your activity is being destroyed in the am_finish_activity and/or am_destroy_activity print in the event log. Example from me leaving Gmail with the BACK button (notice the app-request and finish-imm reasons):

$ adb logcat -bevents
I/am_finish_activity( 1155): [0,947820256,3228,com.google.android.gm/.ConversationListActivityGmail,app-request]
I/am_pause_activity( 1155): [0,947820256,com.google.android.gm/.ConversationListActivityGmail]
I/am_on_paused_called(17619): [0,com.google.android.gm.ConversationListActivityGmail]
I/am_home_stack_moved( 1155): [0,1,0,0,prevFinished]
I/wm_task_moved( 1155): [3162,1,1]
I/am_focused_activity( 1155): [0,com.android.launcher/com.android.launcher2.Launcher]
I/am_resume_activity( 1155): [0,285205047,3162,com.android.launcher/com.android.launcher2.Launcher]
I/am_on_resume_called(24956): [0,com.android.launcher2.Launcher]
I/am_destroy_activity( 1155): [0,947820256,3228,com.google.android.gm/.ConversationListActivityGmail,finish-imm]

Not sure how detailed those reason strings get, but if you're really having a hard time figuring it out, it's worth a look.

like image 147
Snild Dolkow Avatar answered Nov 15 '22 08:11

Snild Dolkow