0

我在我的应用程序中使用 singleTask 活动。订购活动 A->B->C->B 我在 A 上加了额外的,然后在 B 上得到它,然后我去 C 并尝试putExtraB,但在 BI 上看不到它。

如果我使用 default android:launchMode,它可以正常工作。

4

1 回答 1

1

你必须在意图之间携带额外的东西。

A -step1-> B -step2-> C -step3-> B

步骤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);
    };

第2步

        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);
        };

第三步

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);
};
于 2012-12-26T12:02:11.227 回答