0

ボタン Aでこれを呼び出してアプリを起動しようとしているアプリ (「SendingApp」と呼びましょう) があります。

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.sendingapp");
launchIntent.putExtra("my_extra", "AAAA"));
startActivity(launchIntent);

これはボタン Bにあります:

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.sendingapp");
launchIntent.putExtra("my_extra", "BBBB"));
startActivity(launchIntent);

私自身のアプリ (「RecomingApp」と呼びましょう) では、マニフェストで次のように定義されたランチャー アクティビティがあります。

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".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>
</application>

RecomingApp のMainActivityクラスの onCreate メソッドで、余分なものを受け取り、次のように TextView に出力します。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Intent intent = getIntent();
    if(intent != null) {
        Bundle extras = intent.getExtras();
        if(extras != null && extras.getString("my_extra") != null){
            ((TextView)findViewById(R.id.test_text)).setText(extras.getString("my_extra"));
        } else {
            ((TextView)findViewById(R.id.test_text)).setText("NORMAL START");
        }
    }
}

アイコンをタップするか、Eclipse からデバッグを開始することで、RecomingApp を正常に起動すると、正常に動作し、TextView には「NORMAL START」と表示されます。

次に、戻るボタンを押して RecomingApp を閉じ、SendingApp に移動してボタン A を押すと、RecomingApp が起動し、AAAA が表示されます。もう一度戻ってボタン B を押すと、RecomingApp が起動され、BBBB が表示されます。ここまでは順調ですね。

タスク リストまたはアプリケーション マネージャーで RecomingApp を強制終了し、SendingApp に移動してボタン A を押すと、RecomingApp が起動して AAAA が表示されますが (それでも正しい)、戻ってボタン B を押すと、 RecomingApp は起動しますが、 onCreateを呼び出しません。そのため、BBBB は表示されませんが、AAAA は表示されます。これは、フォアグラウンドに移動されたがインテントを受信して​​いないのと同じです。RecomingApp で [戻る] ボタンを押すと、MainActivity の新しいインスタンスがアクティビティのスタックに置かれていないことも示されます。

RecomingApp を閉じて、アイコンをクリックして起動すると、この動作が修正されます。ただし、最初のインテントを受信したときに実行されていなかった場合でも、さまざまなインテントを受信できるようにする必要があります。

以前にこの動作に遭遇した人はいますか? データを受信するコードが間違っているのでしょうか、それとも Android のバグでしょうか?

4

0 に答える 0