使用下面的代码可以做到跟点击app应用图标一样的效果,(如果在后台 就带到前台, 如果没有就打开新的app)
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setClass(this, Main.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
引用
除了 setClass 可以换成使用 setClassName 绑定,FLAG_ACTIVITY_RESET_TASK_IF_NEEDED可以不设,其他的选项都缺一不可。设置ACTION_MAIN与CATEGORY_LAUNCHER是把该Intent发给了系统对应创建程序的模块,然后系统该模块根据设定的包与类信息还有flags进行处理。当然所有的Intent工作原理都是这样,只是对 ACTION_MAIN - CATEGORY_LAUNCHAR 的处理较为特殊,使得总是显示Task栈顶的Activity而不是setClass设定的Activity类。
http://www.cnblogs.com/SteveMing/archive/2012/04/24/2459575.html
http://developer.android.com/guide/components/tasks-and-back-stack.html
分享到:
相关推荐
android Intent.FLAG大全
本代码为博客代码,博客地址:http://blog.csdn.net/zhangjinhuang
Intent可以携带一些数据,比如基本类型数据int、Boolean,或是String,或是序列化对象,Parcelable与Serializable。 Intent传递数据时,如果数据太大,可能会出现异常。比如App闪退,或是Intent发送不成功,logcat...
Intents and Intent Filters 三种应用程序基本组件——activity, service和broadcast receiver——是使用称为intent的消息来激活的。Intent消息传递是一种组件间运行时绑定的机制. intent是Intent对象, 它包含了...
IntentIntent-Filter思维导图
intent startactivityforresult setResult intent
主要实现了对intent属性的一些测试,以及使用intent时的一些注意事项。
android Intent例子源码android Intent例子源码android Intent例子源码android Intent例子源码android Intent例子源码android Intent例子源码
Intent 与 Intent Filters 实现外部调用
intent的常用方法 Intent在Android中的几种用法 文章分类:综合技术
Android源代码 演示3个功能: (1)Intent打开另外一个Activity (2)Intent拨电话 (3)Intent在2个Activity间传递数据
Android应用源码之Intent_Intent
这里总结一些重用的Intent使用,仅供参考。 下面直接给我学习的实例片段。 1,调用web浏览器 Uri myBlogUri = Uri.parse("http://kuikui.javaeye.com"); returnIt = new Intent(Intent.ACTION_VIEW, myBlogUri); 2...
使用Intent打开网页
intent属性
android整合--intent
使用Intent拨打电话
Activity生命周期及Intent传值
intent 传递对象,主要是通过intent传递自定义对象
Intent界面的跳转 public void onClick View v { TODO Auto generated method stub Intent intent new Intent MainActivity this SecondActivity class ; 一定要在配置文件中声明SecondActivity ...