0

i have developed application that consists of A activity (luncher), B activity (second), C activity (third),

what i have tried is :

when the screen is locked or turned off as you are away from the device or have pressed the power button to locked it, my goal is C activity finished and when you turn the screen on again A activity start.

Note : i'm new to android and java development .

i think we can use onPause(), method or onStop(), method for that purpose, but it acually does not work with me as below code in C activity :

protected void onPause(){
  super.onPause();
  Intent i = new Intent(this,A activity);
  startActivity(i);
}

when i lock screen and it become black then open again it still has C activity there.

any advice to get that with onPause(), method or onStop(), method or other ways to get it, thanks

caitriona
  • 8,569
  • 4
  • 32
  • 36

2 Answers2

0

in C Activity - onPause method you can try using this code:

new Handler().post(new Runnable() {

                             @Override
                             public void run()
                             {
                            Intent intent = new Intent(this,A activity);
                                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
                                overridePendingTransition(0, 0);
                                finish();

                                overridePendingTransition(0, 0);
                                startActivity(intent);
                            }

this will close current activity and open selected activity.

Hope it helps.

Adrian C.
  • 1,647
  • 1
  • 23
  • 27
-1

I am not sure but try this way:-

 protected void onPause()
{

    Intent i = new Intent(this,A activity);
   startActivity(i); 
   super.onPause();
}
Mehul Ranpara
  • 4,245
  • 2
  • 26
  • 39
  • when i use your code its ok when screen lock and open again it shift to A activity but the problem that code prevent shift from to B activity to C activity also , when press in B activity go directly to A activity also, thanks – coldfrozen4 Oct 31 '12 at 12:45