简体   繁体   中英

Navigate to previous Activity

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 .

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.

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).

尝试使用Thread.sleep([ms])然后调用完成或调用intent到第一个

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.

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