0

How can i go back to previous activity(List) with closing current activity(Save) in android I tried the below code

public  void  cancel() {
   Intent intent = new Intent(Save.this, List.class );
   startActivityForResult(intent, TIME_ENTRY_REQUEST_CODE);     
}

but while running unfortunately my app is stopped.. can any one help me?

War10ck
  • 12,387
  • 7
  • 41
  • 54
viki
  • 1
  • 3

3 Answers3

0

try

public void cancel() {
  finish();
}
Guy
  • 12,250
  • 6
  • 53
  • 70
0

If you are using startActivityForResult to start a activity , then you can use finishActivity() to finish the activity and go back to the previous activity. To give you better understanding , i am adding the following stack overflow link.

Android:Go back to previous activity

Code

public void gobacktoprious()
{
finishActivity();
}
Community
  • 1
  • 1
Balaji Sabdhar M
  • 418
  • 1
  • 6
  • 26
0

Try this it handles when user clicks back key

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if ((keyCode == KeyEvent.KEYCODE_BACK))
    {
        finish();
    }
    return super.onKeyDown(keyCode, event);
}

}

Elias Sh.
  • 510
  • 6
  • 11