Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent Extras of GCMIntentService is not passed

I coded GCMIntentService but called Activity cannot get the Extras.

@Override
protected void onMessage(Context context, Intent intent) {

    Intent resultIntent = new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
            Intent.FLAG_ACTIVITY_SINGLE_TOP);
        resultIntent.putExtra("PushType", "test"); // Put String Extra.

    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}

and called MainActivity is coded as below.

@Override
protected void onResume() {
    super.onResume();

    final Intent receivedIntent = getIntent();

    if (receivedIntent != null && receivedIntent.hasExtra("PushType")) {
            // Breakpoint at here. but no Extras are given.
        }       
    }
}

I made breakpoint at the receivedIntent and mExtras inside of it shows null.

Additionally, my called MainActivity manifest is coded as below.

        <activity
        android:name=".MainActivity"
        android:theme="@android:style/Theme.NoTitleBar"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:label="@string/app_name">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>

I changed called intent to another Activity and it successfully loads Extras. The manifest of substitute activity (which successfully contains Extras) was as below.

        <activity
        android:name=".NotificationActivity"
        android:parentActivityName=".MainActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity"/>
    </activity>

What did I wrong?

like image 414
Youngjae Avatar asked Nov 18 '25 21:11

Youngjae


1 Answers

It looks like you need to override onNewIntent(Intent intent) method and inside onNewIntent() call setIntent(intent). Then onResume() will pick up the new intent. See onNewIntent() for more detail.

like image 197
Y2i Avatar answered Nov 21 '25 12:11

Y2i