0

I have an Android app in which activity A calls activity B which calls activity C. in activity C there is button to restart the whole thing but the user should be able to navigate between the activities if he presses the back button.

I've tried startActivityForResult(intent,int) and sending close all the way back but in this case, if the user clicks the back button, it collapses all the previous activities regardless of pressing the restart button on activity C.

Anyone knows how to solve this?

Himanshu
  • 31,810
  • 31
  • 111
  • 133
DAndroid
  • 3
  • 3
  • you should manage your activity life cycle below link can help you http://developer.android.com/training/basics/activity-lifecycle/index.html – Hardik Nadiyapara Jul 28 '12 at 08:14

2 Answers2

0

I did not get your point completely,

As far I understood you should use finish(), before intent statement on each activity

Romio
  • 140
  • 1
  • 8
  • activity A has in onActivityResult - if requestCode==2 then finish(); and launches B with startActivityForResult(i,2); activity B has in onActivityResult - if requestCode==2 then finish(); and launches c with startActivityForResult(i,2); activity C has in setResult(2) and finish(); The result is that it closes the activities not only when pressed close on activity C but also when the user presses the back_btn on activity B. – DAndroid Jul 28 '12 at 08:19
0

You can use setResult(). For example when the user taps button "restart" in activity C, you set result code to your custom one (10 for example). In A, B, you get the code (in onActivityResult()) and handle it.

Anh3Saigon
  • 199
  • 5
  • This way, if the user simply goes back from B to A it collapses everything. I solved it using a Pref (true/false)... Thx! – DAndroid Jul 29 '12 at 11:24