android:launchMode="singleTop"
来源:互联网 发布:cnc编程学徒 编辑:程序博客网 时间:2024/05/17 05:56
Android: new Intent() starts new instance with android:launchMode="singleTop"
I have Activity A
with android:launchMode="singleTop"
in the manifest.
If I go to Activity B
, C
and D
there I have menu shortcuts to return to my applications root activity (A
).
The code looks like this:
startActivity(myIntent);
it creates a new instance -> it goes to onCreate() instead of onNewIntent().
This is not the expected behavior, right?
Answer3:
<activity ... android:launchMode="singleTop" />
When you create an intent to start the app use:
Intent intent=new Intent(context, YourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
This is that should be needed.
Answer by PHP_Jedi
Answer2:
The "standard" and "singleTop" modes differ from each other in just one respect: Every time there's new intent for a "standard" activity, a new instance of the class is created to respond to that intent. Each instance handles a single intent. Similarly, a new instance of a "singleTop" activity may also be created to handle a new intent. However, if the target task already has an existing instance of the activity at the top of its stack, that instance will receive the new intent (in an onNewIntent() call); a new instance is not created.
I'm not 100% sure what "already has an existing instance of the activity at the top of its stack" means, but perhaps your activity isn't meeting this condition.
Would singleTask
or singleInstance
work for you? Or perhaps you could try setting FLAG_ACTIVITY_SINGLE_TOP
on the intent you are creating to see if that makes a difference, although I don't think it will.
Answer by mbaird
So if my will is to launch a new instance of activity in the same proccess, but i already FOCUSED on a previouse instance of that activity, how would i do that? – rayman Jul 14 at 7:31
Answer1:
Intent myIntent = new Intent(getBaseContext(), MainActivity.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(myIntent);
- android:launchMode="singleTop"
- android:launchMode="singleTop"
- Activity launchMode四分之二 ----singleTop
- 理解Android的Activity launchMode:standard,singleTop,singleTask,singleInstance
- Understand Android Activity's launchMode: standard, singleTop, singleTask and singleInstance
- Understand Android Activity's launchMode: standard, singleTop, singleTask and singleInstance
- 理解Android的Activity launchMode:standard,singleTop,singleTask,singleInstance
- Android Trick 4: Activity的android:launchMode (startard、singleTop、singleTask、singleInstance)
- Activity的launchMode:singleTop,singleTask与singleInstance
- Activity的launchMode:singleTop,singleTask与singleInstance
- Activity之launchMode:singleTop,singleTask与singleInstance
- Activity的launchMode:singleTop,singleTask与singleInstance
- android:launchMode="singleTask"
- 关于android:launchMode=“singleInstance”
- 关于android:launchMode=“singleInstance”
- Android singleTop的应用
- android launchMode
- Android launchMode
- 什么是FRBR,我今天弄明白了
- 判断电脑待机
- 在windows2003 server 上安装svn以及客户端密码修改
- 使用 Windows Media Format 9 Series SDK 添加 Windows Media 支持
- jdbc对SqlServer以及java数据类型映射表(很有用的)
- android:launchMode="singleTop"
- 使用 Windows Media Format 9 Series SDK 添加 Windows Media 支持
- 模态框提交表单不打开新页面的解决方法
- c++ 程序员成长书单
- 用批处理来开启远程控制
- u-boot移植详细文档
- 装载问题解决
- 谈谈网站完全改变内容 让百度GOOGLE重新收录的经验
- SQL2008 SSIS Excel 导入目标数据库,报“...because more than one code page...”