0

Lets say i have a few activity A,B and C.

Activity A is run on application start. It is supposed to do a asyntask in the background automatically to login to a server based on imei, also starting a service. If login is failed activity A will have a refresh button for user to rerun the asyn task. After login is done, the activity is being finished by finish() and flow to B then to C.

There is 2 problem faced.

  1. At any point of time if the user were to re-run the application via app menu, activity A will run again which result in unnecessary login and running of some background service.

  2. At activity C when i press Back it returns to B and then back which returns to main menu, which is correct. however when i press Home button and select back the app the application reruns activity A again.

ericlee
  • 2,703
  • 11
  • 43
  • 68

3 Answers3

0

in your manifest file, set your launcher activity to run as "single-task"

android:launchMode="singleTask"
josephus
  • 8,284
  • 1
  • 37
  • 57
  • what does this does? any other comments? – ericlee Nov 01 '11 at 16:56
  • this tells your application that you only want one instance of it running. in other words, when you're in activity B or C, and pressed Home, then launched the application again, you will end up where you left. if it doesn't work, try singleInstance – josephus Nov 02 '11 at 01:00
0

I understand one thing from your app.. the app flows from a screen A(Login) --> to Screen B and later to Screen C ... The app cannot propogate to Screen C Directly.

now... at the very start of the app you can have a stored data to check whether you have already logged in and the background threads you wanted have been completed. once that is checked.. you can manually redirtect with an new intent to screen B .... I think this answers to the first point.

second... I think it is a normal behavior to restart the app if that is the that you want to store the app's state in the onpause and onStop methods so that app starts from where you left off..

medampudi
  • 399
  • 3
  • 15
  • Lets say i am at screen C. If i were to start the app from app menu, i will have to manual redirect to activity C? – ericlee Nov 01 '11 at 17:03
  • have a look at [this](http://stackoverflow.com/questions/151777/how-do-i-save-an-android-applications-state) and [this](http://stackoverflow.com/questions/4765389/android-saving-application-state-when-going-to-the-background) also please check the Android Developer library for pointers too.... – medampudi Nov 01 '11 at 17:08
0

Ur second problem has a sure-shot solution. Add this tag in ur launcher activity::

      android:alwaysRetainTaskState="true"

Cheers....!!!

Rohit
  • 593
  • 2
  • 8