需要$ C $下退出的Andr​​oid应用程序 [英] Need code for exit from app in android

查看:98
本文介绍了需要$ C $下退出的Andr​​oid应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是新来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

这篇关于需要$ C $下退出的Andr​​oid应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆