1

I have developed an android application. According to requirement, data should only be fetched once from server in all activities and activity state should be save, so when user out of that screen and landed to that activity again it will see same preview again as it has left. I have achieved this with following attributes in Activity tag.

android:launchMode="singleInstance"
android:alwaysRetainTaskState="true"

Now Problem is that every activity is creating its instance. i want user to get out of application when user press Back button. i Am Overiding my back button with home button. here is the code i am using.

Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);

But when user click again app icon application open opening again from the screen which was left previewed rather than starting from launching screen. what is the best solution to close application in my case and start from launching activity again. please help me. i need help. Thanks in Advance.

rizwan
  • 71
  • 6
  • 2
    What you are doing looks a bit strange to me. I would use `onSavedInstanceState()` in the activity to save and my activity's state. If you need more, for instance preserving state if user clicks back, then persist your data on disk, for example in SharedPreferences, SQLite databases or Files. – Gil Vegliach Dec 06 '15 at 18:37
  • yes bit strange. i give you an example y i did this. user open webview, scroll down to 10th item and expand it and mark one icon and go to other screen and came to screen again. now he will see the webview with expand and mark icon. how should i handled this ??? – rizwan Dec 06 '15 at 18:49
  • i have google it. came to stackoverflow and follow this link.http://stackoverflow.com/questions/28096779/how-to-save-webview-state-and-restore-it-in-android-lollipop – rizwan Dec 06 '15 at 18:55
  • Are you calling `finish()` in your overridden `onBackPressed()` method? You need to call `finish()` to ensure that your `Activity` gets destroyed. – David Wasser Apr 18 '17 at 18:23

0 Answers0