Set Intent to the return key in TabActivity

I have three actions - AB and C, of ​​which B is the Tab tab . First, action A starts, and B starts from A. I end operation A when B starts using this code.

public void onStop() {
   super.onStop();
   this.finish();
}

Now I want to start Activity C when the back key is pressed in B.

I tried overriding the key with this code

@Override 
public void onBackPressed() { this.getParent().onBackPressed();
}

This does not help when the parent activity ends when the child process starts. What actually happens when I press the back key is that the action goes to the main screen.

I tried to override the return key and set the intent for it

@Override
public void onBackPressed() {
    Intent backIntent = new Intent();
    backIntent.setClass(this, main.class);
    startActivity(backIntent);
}

That doesn't help either. What could be a possible solution to this problem? How to start Activity C when I press the back key?

+3
3

A, A , B.

Intent i = new Intent(this, B.class);
startActivity(i);
finish();

C, "", .

@Override
public void onBackPressed() {
    Intent backIntent = new Intent(this, C.class);
    startActivity(backIntent);
    super.onBackPressed();
}
+5

onKeyDown

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub

    if (keyCode == event.KEYCODE_BACK)
    {
        //Do your code here
    }
    return super.onKeyDown(keyCode, event);
}
}

, .

:   StartActivity ( Intent (getApplicationContext(), main.class));

+1

.....

public boolean onKeyDown(int keyCode, KeyEvent event) 
{
// TODO Auto-generated method stub

   if (keyCode == event.KEYCODE_BACK)
   {
      //Write your intent or other code here
   }
   return super.onKeyDown(keyCode, event);
}
0

All Articles