1

I am developing an Android application. I want to quit my application but application should be in running state in background. Whenever I click on application application should start from last quit point. I dont want to login again.

The same thing is happening when I press home button. But I want to implement similar functionality like Home button on my own button event. How should I proceed with that??

Though I have finished all other activities, still I need to login again. When I finish the activity my session ends there. And on next app start with login screen.

Whereas in case of home button click, it keeps my session and on next app start my app check onResume() event where I am checking whether session exist or not. If session is there I can enter directly into my account.

So Anybody have any idea what exactly android does when we press home button.

  • Guess you want to do something like this: http://stackoverflow.com/questions/151777/how-do-i-save-an-android-applications-state however if you want to leave some code running in the background you need to move it to a service since a non active activity can be killed by the os if resources is needed. – Fredrik Leijon Sep 14 '11 at 08:42
  • Duplicate of http://stackoverflow.com/questions/7403945/need-help-for-closing-my-android-app – Jasoneer Sep 14 '11 at 09:12

4 Answers4

0

You mean login to a web app? WebView saves cookie information application-wide regardless of activity.

Otherwise use a static variable or singleton class to hold any session state and on activity start, check the static variable or singleton class for any state else redirect them to the login screen.

Jasoneer
  • 2,078
  • 2
  • 15
  • 20
0

You can call moveTaskToBack on your Activity.

ZehnVon12
  • 4,026
  • 3
  • 19
  • 23
0

The best way I know is something like in your scenario where you want to quit:

  1. Save the login credentials on login and clear on log out.
  2. When your app launches check for credentials and if it is there then you should login without asking user.

The above process will not bring your last activity but the activity which you show after login.

To bring back the last activity where you quit, you can use moveTasktoback(true) as it will put your app in the background the same when you press Home key but it's behaviour will not remain constant as android can kill your app whenever it will require the memory.

Vineet Shukla
  • 23,865
  • 10
  • 55
  • 63
0

create a button where you want to pause(i mean in which activity) the application. And write the code like below. This will pause your application.

button.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {

                moveTaskToBack(true);
            }

        });
ilango j
  • 5,967
  • 2
  • 28
  • 25