简体   繁体   中英

Android: Activity is not destroyed using the command 'finishActivity(999)'

My currently running activity B should be destroyed using 'finishActivity(999)'. Doing so, I want to get back to the method 'onActivityResult' in activity A which called activity B. This somehow doesn't work. Below some code snippets:

public class ActivityB extends Activity {
  ...

  // Method listening OnClick event
  public void verifyPassword(View view) {
  ...
  // call http server in order to verify password
  if (httpResponse != 200) {
    finishActivity(999);
  }
  command Z;
}

I can see that in the debugger that the finishActivity(999) statement is performed, but after that, simply the next instruction 'command Z' in the same activiy is executed.

Why does the finishActivity(999) statement has no effect?

finishActivity() doesn't finish the current activity:

Force finish another activity that you had previously started with startActivityForResult(Intent, int).

Note another activity , not this activity (eg you could call it from activity a).

You want just finish() instead, most likely in combination with setResult() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM