活动A启动活动B,没有标记.堆栈现在是AB,顶部是B. B使用FLAG_ACTIVITY_REORDER_TO_FRONT(唯一标志)启动活动A. 我希望这个堆栈现在是BA.但是,当此时按下后退按钮时,它将返回主屏幕.在这里,我希望将活动B带到前面.再次单击启动器图标后,应用程序将打开,其中B作为运行活动,堆栈中没有任何内容.
Launchmode是清单中的标准(默认).
这是预期的行为,我只是不理解它?
编辑:我创建了一个没有混淆因素的测试项目,仍然看到相同的行为.我只是不明白它,它似乎不是每个文档.
编辑:对我来说这个行为似乎是框架中的一个BUG,请参阅下面的答案我的评论.我需要一个解决方法.
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void onClickBtn(View view) { Intent flowIntent = new Intent(this, SecondActivity.class); startActivity(flowIntent); }
}
public class SecondActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void onClickBtn(View view) { Intent flowIntent = new Intent(this, MainActivity.class); flowIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(flowIntent); }
}
清单:
} public class SecondActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void onClickBtn(View view) { Intent flowIntent = new Intent(this, SecondActivity.class); startActivity(flowIntent); }
}
或者 } public class SecondActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
} }
它转到另一台PC,添加它@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onClickBtn(View view)
{
Intent flowIntent = new Intent(this, MainActivity.class);
flowIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(flowIntent);
}
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void onClickBtn(View view) { Intent flowIntent = new Intent(this, SecondActivity.class); startActivity(flowIntent); }
}
public class SecondActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void onClickBtn(View view) { Intent flowIntent = new Intent(this, MainActivity.class); flowIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(flowIntent); }
} ;-)
有关详细步骤,请查看此问题 } public class SecondActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void onClickBtn(View view) { Intent flowIntent = new Intent(this, SecondActivity.class); startActivity(flowIntent); }
} 是否有任何方法可以克隆已安装的流浪盒
http://code.google.com/p/android/issues/detail?id=63570#c2
它已被谷歌确认为4.4.2的错误
我找到了这个bug的简单解决方法.
覆盖onNewIntent并完成任何可能重新排序到前台活动的功能,如下所示,只是不完全测试,如果您发现此解决方法有任何问题,请通过ricotta.zhang@myriadgroup.com与我联系
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if ((intent.getFlags() | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) > 0) { mIsRestoredToTop = true; } } @Override public void finish() { super.finish(); if (android.os.Build.VERSION.SDK_INT >= 19 && !isTaskRoot() && mIsRestoredToTop) { // 4.4.2 platform issues for FLAG_ACTIVITY_REORDER_TO_FRONT, // reordered activity back press will go to home unexpectly, // Workaround: move reordered activity current task to front when it's finished. ActivityManager tasksManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); tasksManager.moveTaskToFront(getTaskId(), ActivityManager.MOVE_TASK_NO_USER_ACTION); } }
首先,让我们先说你是对的!
但是如果我的逻辑是正确的,那么当你REORDER
进入你的主Activity
(the Launcher
Activity
)时会发生什么,Intent被设置为使得后退将返回到你的Launcher
.
作为实验,尝试添加Activity
C并尝试REORDER
从C到前面的B.即:
A-> B-> C ... A-> C-> B
如果订单对您非常重要,则可能需要覆盖Activity.onNewIntent()方法.
@Override protected void onNewIntent(Intent intent) { }