1

I have Activity A that starts another Activity B.

When I am in Activity B I should be able to close both A and B.

For this purpose I used the approach at this link https://stackoverflow.com/a/11509279/1815311, but sometimes I get a NullPointerException when I do aActivity.handleToClose.finish();

Please what possibly can be wrong here???

Community
  • 1
  • 1
Lisa Anne
  • 4,482
  • 17
  • 83
  • 157

1 Answers1

1

That happens because your Activity A is closed form some reason and when you call you method to close that activity you get null pointer exception.

The solution is to check if Activity A is finished or not, if it is finished than you dont need to call finish

Ultimo_m
  • 4,724
  • 4
  • 38
  • 60
  • thanks Ultimo, I see this could be the cause, but I an not closing A, so I do not understand how possibility can it be closed... any idea? Thanks. LISA – Lisa Anne Jun 08 '14 at 11:06
  • There are 2 options: Android closes this Activity or when you start Activity with intent you have put any flag that clears activity stack – Ultimo_m Jun 08 '14 at 11:11
  • mmmm I do not to the latter; the former: is it likely under normal circumstances? I do not think so – Lisa Anne Jun 08 '14 at 11:13
  • 1
    To check if Android System closes your activity you can debug the code, or see if it is called the onDestroy of ActivityA – Ultimo_m Jun 08 '14 at 11:16