我在我的应用程序中使用singleTask活动。
订购活动A-> B-> C-> B
我把额外的东西放在A上,然后把它拿到B上,然后我去C并尝试putExtra
代表B,但是在B我看不到它。
如果我使用默认android:launchMode
,则可以正常使用。
答案 0 :(得分:1)
你必须在意图之间携带额外的东西。
A -step1-> B-step2-> C-step3->乙
<强>步骤1 强>
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String extraString;
Bundle extras = getIntent().getExtras();
if (extras == null) {
extraString = null;
System.out.println("null extra");
} else {
extraString = extras.getString("extra");
System.out.println("from " + extraString);
}
Intent intent = new Intent(C.this,B.class);
intent.putExtra("extra", extraString);
startActivity(intent);
};
step2
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String extraString,extraString2;
Bundle extras = getIntent().getExtras();
if (extras == null) {
extraString = null;
System.out.println("null extra");
} else {
try
{
extraString = extras.getString("extra");
System.out.println("from " + extraString);
{
catch{}
}
// CATCH EXTRA STRING2
if (extras == null) {
extraString2 = null;
System.out.println("null extra");
} else {
try
{
extraString2 = extras.getString("extra2");
System.out.println("from " + extraString2);
{
catch{}
}
Intent intent = new Intent(C.this,B.class);
intent.putExtra("extra", extraString);
startActivity(intent);
};
<强>步骤3 强>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String extraString
Bundle extras = getIntent().getExtras();
if (extras == null) {
extraString = null;
System.out.println("null extra");
} else {
extraString = extras.getString("extra");
System.out.println("from " + extraString);
}
Intent intent = new Intent(C.this,B.class);
intent.putExtra("extra2", extraString);
startActivity(intent);
};