我正在我的应用程序中创建一个测验,显示分数后它将返回到活动“ NavigActivity”,但是我想知道如何更改此代码以返回片段,这是底部导航中的第二个图标酒吧?我希望它返回的片段是DashboardFragment
Toast.makeText(getApplicationContext(), "Your score: " + percentage + "%", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(EmotionsActivity.this, NavigActivity.class);
startActivity(i);
finish();
}
}, 3000); // Set your time here //
答案 0 :(得分:0)
通过run()方法从EmotionsActivity.java中传递一个额外的信息:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(EmotionsActivity.this, NavigActivity.class);
i.putExtra("unique_id", "from_emotions_activity");
startActivity(i);
finish();
}
}, 3000); // Set your time here //
以及您的NavigActivity
onCreate()
方法中:
String fromWhichActivity = getIntent().getStringExtra("unique_id");
if (fromWhichActivity.equals("from_emotions_activity") {
// perform fragmentTranaction...add/replace....commit
}