1

In my application, There is an activity UserMenu, in which (at on create) subsequent loading is done. I want that next time when the application is opened, this screen should not be reloaded again - I want to save the state of the UserMenu screen as it is.

I have been moving through this, but I am unable to look what I have to implement, I dont want to save any values, simply I want to recreate the same screen as I can get on pressing the home button in android.

Kindly help me regarding my matter.

Thanks

Community
  • 1
  • 1
Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
  • can you describe subsequent loading in brief?what exactly do you want to save as the state of your screen? – Mehul Joisar Mar 08 '13 at 06:56
  • I have an expandable list view and that gets loaded with its arraylists for the group and child and also in the asynctask some API are calling in the background – Gaurav Arora Mar 08 '13 at 06:59

3 Answers3

0

You can do like this

In your UserMenu Activity class

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            goToHome();
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

    private void goToHome() {
        moveTaskToBack(true);

    }

So when you will press back button the Activity will no be destroyed and move to Home and once you will long press Home Button or start your app from menu it wont load the Activity again.

Thanks

Amit Gupta
  • 8,914
  • 1
  • 25
  • 33
0

It is not possible according to me as like what you are saying about home button. when home button is pressed your activity goes in onPause() and when you reopen it comes in onResume(). You can do what is suggested in the link you are following i.e you can save the values of your Actvity elements using onSavedInstanceState() also it is no guaranteed to execute read this onSavedInstanceState

Siddhesh
  • 1,370
  • 11
  • 28
0

you need to follow the Activity Lifecycle to make it simple.just make a function call from onCreate() method to load those data,save the data in some standalone class using ArrayList(),and in onResume() display the stored data from ArrayList().and yes,inside onCreate() check for the size of that ArrayList() just to decide whether the data has already been loaded or not.if it has not been loaded,load it.otherwise don't load.

Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57