【发布时间】:2018-04-24 06:29:33
【问题描述】:
活动 A 在没有标志的情况下启动活动 B。堆栈现在是 A-B,B 在顶部。 B 使用 FLAG_ACTIVITY_REORDER_TO_FRONT(唯一的标志)启动活动 A。我希望堆栈现在是 B-A。但是,此时按下后退按钮时,它会返回主屏幕。在这里,我希望将活动 B 带到最前面。再次单击启动器图标后,应用将打开,其中 B 作为正在运行的 Activity,堆栈中没有任何内容。
启动模式是清单中的标准(默认)。
这是预期的行为,我只是没有正确理解它吗?
编辑:我创建了一个没有混淆因素的测试项目,但仍然看到相同的行为。我只是不明白,它似乎不符合文档。
编辑:对我来说,这种行为似乎是框架中的一个错误,请参阅下面我对答案的评论。我需要一个解决方法。
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);
}
}
公共类 SecondActivity 扩展了 Activity { @覆盖 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);
}
}
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="@987654321@;
package="com.example.tester"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.tester.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.tester.SecondActivity" />
</application>
</manifest>
【问题讨论】:
-
能否请您发布您的清单?
-
请发布您的主题
标签: android