没有收到意向演员 [英] Intent extras not received

查看:93
本文介绍了没有收到意向演员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我显示从连接到我的项目库的通知,在通知点击后,通知需要到活动(ReceivingActivity)。活动开启点击通知后,却没有收到重视它的花絮。

I am showing a notification from a library attached to my project, when clicked on the notification, the notification takes to an Activity (ReceivingActivity). Activity opens after clicking the notification ,but the extras attached to it are not received.

通知触发code - 我称之为 sendNotification的当我收到一个GCM消息和通知code是在库

Notification triggering code - I call sendNotification when i receive a gcm message and Notification code is in the library

public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
private void sendNotification(Bundle extras) {
    mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);



    Intent redirectIntent = new Intent(this, Class.forName("com.xyz.kljdf.ReceivingActivity"));
            redirectIntent.putExtra("key", "value"); // These extras are not received in ReceivingActivity onCreate(), see the code below




    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            redirectIntent, 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
    .setSmallIcon(((Context)this).getResources().getIdentifier("icon", "drawable", getPackageName()))
    .setContentTitle(extras.getString(PushConstants.TITLE))
    .setStyle(new NotificationCompat.BigTextStyle()
    .bigText(extras.getString(PushConstants.ALERT)))
    .setContentText(extras.getString(PushConstants.ALERT));

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

检查额外的ReceivingActivity ...

Checking the extras in the ReceivingActivity...

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_receiving);


        Log.i("extras..... @@@@@@", getIntent().getExtras().toString()); //NPE here


    }

我需要搞清楚如何通过演员和正确地接收他们的帮助。

I need help in figuring out how to pass the extras and receive them correctly.

推荐答案

请确保该PendingIntent实际传递数据时,它被称为。看到这个答案的解释: http://stackoverflow.com/a/3851414/1426565

Make sure the PendingIntent is actually passing the data when it's called. See this answer for an explanation: http://stackoverflow.com/a/3851414/1426565

有关其他任何人,如果你是积极的意图已经存在,并且是刚刚带到前面,新意图的数据将不会被传递给它的默认值。你可以为了得到周围覆盖onNewIntent(意向):

For anyone else, if you're positive the intent already exists and is just brought to the front, the new Intent's data won't be passed to it by default. You can override onNewIntent(Intent) in order to get around that:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent); // Set the new Intent's data to be the currently passed arguments
}

这篇关于没有收到意向演员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆