0

I am trying to develop an android app which supports from 2.3 and above to the latest version. and it is session based. Scenario: My app as a login activity and on successful login it starts the A activity and further activities can be started like A activity->B activity->C activity. My question is: when I am in C-activity and if session expires(Session expiry is from the server side),I need to close all the activities in the task and start a new Login activity.

I tried using FLAG_ACTIVITY_CLEAR_TASK (but this flags supports from 3.0).please help me with a solution.

Robin prash
  • 153
  • 1
  • 1
  • 6
  • Have a look at this thread: http://stackoverflow.com/questions/12947916/android-remove-all-the-previous-activities-from-the-back-stack – Suji Jul 26 '13 at 17:48

2 Answers2

0

You could create a BroadcastReceiver listening for the "expiration" action, create the class that extends from BroadcastReceiver in your activity, register the broadcast to listen for the "expiration" action and onReceive method finish the activity, that would do the trick... Remember to properly manage the register/unregister actions of the broadcast so you dont leak registered broadcast by unregistering already destroyed activities...

Hope it Helps.

Regards!

Martin Cazares
  • 13,637
  • 10
  • 47
  • 54
  • Session expiry is from server side.so when you make a request then only we will come to know whether the session is expired or not. But how do you clear the activities in the task and start a new activity. – Robin prash Jul 27 '13 at 09:09
0

I am doing something similar and what I did was started each activity after the login for a a result. When the expiration happens, just set the activity result to anything you decide and use finish(); It'll look something like this:

Login:

getInfo(){
    yourCode;
    if(correct)
        startActivityForResult(yourIntent);
}

onActivityResult(int requestCode, int resultCode, Intent data){
    if(resultCode == 0)
        yourCode;
}

Activity A:

expiration(){
    setResult(0);
    finish();
}

Just set up each activity's expiration method to finish the activity and set the result code so that the activity before it knows that it should be finishing.

user2483079
  • 533
  • 2
  • 10