-2

There is a android library. workflow like that:

A1->A2-A3->Library activity->A3

I need to hide library activity when user click physical back button. Also, the library activity saved some data, so that I cannot destroy or finish() the library activity.

A1->A2->A3->lib--->return to previous A3

If user press back button, I want to skip the library activity and jump to A2 from A3 but not destroy the library activity because the library activity saved data that I need to use it again.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • please post your code. – santosh gore Mar 22 '17 at 04:37
  • Try using stack – Sagar V Mar 22 '17 at 04:40
  • What kind of data is your library activity holding? Can you use a different way of saving your data instead of holding a whole activity in memory? and also there is a high probability of android OS killing your library activity when it is in the background. – Mohan Krishna Mar 22 '17 at 04:45
  • my library need to capture three screenshot from the application. So that, it need to return to application from library activity when user want to capture the second and the third screenshot. – haha1994713 Mar 22 '17 at 04:54

3 Answers3

2

You should override onBackPressed method in your activity like this:

@Override
public void onBackPressed() {
   super.onBackPressed();
 //change your View from A3 to A2 
}

You can save data using SharedPreferences.

Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
2

If currently visible activity is from the library, and you can not edit the code for it, then it is not possible to handle the backpress of the activity. However, If you are calling this library activity with an Intent from your Activity, What you can do is,
Write a class that extends LibraryActivity and call this activity instead. There you can override the onBackPressed() method.

Shadow
  • 76
  • 5
0

Just make library activity android:noHistory="true" in manifest. And save data you require some where else.

taman neupane
  • 938
  • 9
  • 18