I have two screens, in second screen i have one back button that shows the first screen(using intent). if i click that back button from second screen i navigated to first screen no probs in that.. now i want to navigate back to second screen automatically without clicking any button. Please help me how can i do this. Thanks for ur valuable time .
-
its a little bit unclear that what you want. – Saurabh Pareek Mar 16 '11 at 12:03
-
what exactly is going to trigger the "navigate back to second screen" ? Is there some sort of user interaction or a timeout? – Yashima Mar 16 '11 at 12:08
-
yes i used thread in the second screen,after 2 seconds it should trigger – selva Mar 16 '11 at 12:19
-
Why don't you call the intent in the thread? – Mudassir Mar 16 '11 at 12:21
-
i tried intent, now the problem is state not maintained and it restart the activity. – selva Mar 16 '11 at 13:25
4 Answers
I would give a try to a ViewFlipper
activity, with two screens. This, of course, if you can encapsulate your actions into one activity (which i'm sure is manageable with AsyncTasks
/ Threads
, Services
and Handlers
).
This way you can use gestures, (soft/hard)buttons, dropdowns, -whatever-, to navigate between your screens.

- 19,130
- 7
- 59
- 73
-
its easy..you have knowledge about how to set Dynamic relative layout's child relativity?? – Tofeeq Ahmad May 02 '11 at 08:37
-
You have to use `RelativeLayout.LayoutParams` when adding the new view to the `RelativeLayout`. In that instance you can add rules to where to put the new view. You should take a look at [this question](http://stackoverflow.com/questions/2305395/laying-out-views-in-relativelayout-programmatically), it has a nice example as well. – rekaszeru May 02 '11 at 08:48
You can automatically go back to a previous activity on the Activity stack by calling the finish()
method.
If you want to do this without any user interaction, use a Handler
that automatically calls finish()
on your activity after a predefined timeout (see this article for more information on Handlers).

- 56
- 2
The one solution is, when you press BACK button from second screen instead of call finish(); you should start first activity again, so the activity stack will be
FIRST
SECOND
FIRST
so after the delay of two second your activity will finish and eventually will come back to second screen, and state will be maintained also.

- 1,336
- 10
- 11