在申请重新开张重新启动Android的活动 [英] Restart Android activity on relaunch of application
问题描述
我在Android应用程序有3项活动。该应用程序将退出时,我preSS后退按钮在每个活动。使用下面的code。
当我preSS回来从第三个活动,申请退出正常,但当我重新启动应用程序通过点击应用程序图标,那么第三个活动将再次启动。但我需要启动我的主要活动,在这样的重新开张的时间。
我试着写一篇关于onResume的code,但没有工作。
@覆盖
公共布尔的onkeydown(INT键code,KeyEvent的事件)
{
如果(键code == KeyEvent.KEY code_BACK)
{
moveTaskToBack(真正的);
返回true;
}
返回super.onKeyDown(键code,事件);
}
请帮助我。在此先感谢
- 创建三项活动 - A,B和C
-
在活动A - 调用startActivity(B)时,调用finish()也。示例 -
公共无效onButtonClick()//一些方法 { startActivity(intentForB); 完(); }
-
同样从B到C下 -
公共无效onButtonClick() { startActivity(intentForC); 完(); }
-
当用户在活动℃,当他presses后退按钮,应用程序将得到休息。(无需编写后退按钮明确处理)。
希望这有助于。
I had 3 activities in an android application. The application will exit when I press back button in each activity. Using the following code.
When I press back from the third activity, the application exits fine but when I relaunch the application by clicking the app icon, then the third activity will launch again. But I need to launch my main activity at the time of such "relaunch".
I tried write the code on "onResume" but not working.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
moveTaskToBack(true);
return true;
}
return super.onKeyDown(keyCode, event);
}
Please help me. Thanks in advance
- Create three activities - A, B and C
In Activity A - when calling startActivity(B), call finish() also. Example -
public void onButtonClick() // Some method { startActivity(intentForB); finish(); }
Similarly when going to C from B -
public void onButtonClick() { startActivity(intentForC); finish(); }
When the user is on Activity C and when he presses the back button , the application will get closed.(No need to write back button handling explicitly).
Hope this helps.
这篇关于在申请重新开张重新启动Android的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!