Question

I have a problem with GCM Client. I've received a notification and i've read the message but i can't call "TestView" activity.

This is the GCMIntentService.java:

@Override protected void onMessage(Context context, Intent intent1) {
    String message = intent1.getExtras().getString("message");
    Log.i(TAG, "new message= "+message);
    int icon = R.drawable.icon;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = null;
    notificationIntent = new Intent(context, TestView.class);
    notificationIntent.putExtra("msg", message);
    //notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notificationManager.notify(0, notification);
}

this is the manifest.xml:

 <application
            android:allowBackup="true"
            android:icon="@drawable/icon"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="example.SplashScreen"
                android:label="@string/title_activity_splash_screen"
                android:noHistory="true"
                android:screenOrientation="portrait"
                android:theme="@style/Theme.AppCompat.Light" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name="example.TestView"
                android:label="@string/app_name"
                android:theme="@style/Theme.AppCompat.Light" >
            </activity>
            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />

this is SplahScreen.java:

public class SplashScreen extends ActionBarActivity {
    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen); 
        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();
            //everything is ok, works!
        Bundle extras = getIntent().getExtras();
        String msg = extras.getString("msg");
        Log.d("MSG","msg:"+msg); 
        ...
        new Handler().postDelayed(new Runnable() {   
            @Override  
            public void run() {  
                Intent intent = new Intent(SplashScreen.this,  TestView.class);  
                startActivity(intent);  
                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);  
            }  }, 3);   
        }

and this is TestView.java:

public class TestView extends ActionBarActivity implements ... {
    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        //doesn't work
        Bundle extras = getIntent().getExtras();
        String msg = extras.getString("msg");
        Log.d("MSG","msg:"+msg); 

If i replace :

notificationIntent = new Intent(context, TestView.class);

with:

notificationIntent = new Intent(context, SplashScreen.class);

everything is ok!

I would like to send "message" from "GCMIntentService" to "TestView".

Thank you for any help you can provide in this situation

Was it helpful?

Solution

Try this in your TestView activity:

  public void onNewIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        if (extras != null) { ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top