需要$ C $下退出的Andr​​oid应用程序应用程序、Andr、oid

由网友(﹎银雪娇ゝ℡)分享简介:你好,我是新来android.I正在实施的一些应用程序,它有一定的活动。假设,如果我发动了第一次应用程序,它在进入到A,然后往那个℃后,以B,D,E ......(这里A,B,C,D,E的活动)。如果我$ P在E $ PSS后退按钮,然后它会ð - ç - > B - >像这样的现在我想实现code退出/从应用程序...

你好,我是新来android.I正在实施的一些应用程序,它有一定的活动。 假设,如果我发动了第一次应用程序,它在进入到A,然后往那个℃后,以B,D,E ......(这里A,B,C,D,E的活动)。如果我$ P在E $ PSS后退按钮,然后它会ð - ç - > B - >像这样的

现在我想实现code退出/从应用程序退出时,我在D.           我写了下面的code,但这种code正在为关闭当前的活动,并打算$ P $光伏activity.means要去℃。

  

完成();

然后我试着用以下的code,这是工作的罚款和关闭当前应用程序成功并进入设备主screen.But如果我想再次打开该应用程序,然后它开始表格D,而不是一个。

 意图=新的意图(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(意向);
 

从这里 复制

请帮我解决我的问题。

解决方案

使用这些标志午餐的活动,并明确活动的堆栈

 意向意图=新的意图(这一点,YourActivityD.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(意向);
 

请注意,FLAG_ACTIVITY_CLEAR_TASK只能从API 11 请参阅: http://developer.android.com/guide/components /tasks-and-back-stack.html

Hello i am new to android.I am implementing some application and it have some activities. Suppose if i launch the app for first time,it's entering in to A then going to B after that C,D,E..... (Here A,B,C,D,E are activities).If i press back button at E then it is going D--> C--> B--> A like this.

Now i want to implement code to exit/quit from the app when i am at D. I wrote following code but this code is working for closing current activity and going to prev activity.means going C.

finish();

Then i tried with following code and it is working fine and closing current application successfully and going to device home screen.But if i want open the application again then it is starting form D instead of A.

  intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

copied from here

Please help me to solve my problem.

解决方案

Use these flags to lunch the activity and clear the activity stack

Intent intent = new Intent(this, YourActivityD.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

Be aware that FLAG_ACTIVITY_CLEAR_TASK is only available from API 11 See: http://developer.android.com/guide/components/tasks-and-back-stack.html

阅读全文

相关推荐

最新文章