无法发送数据通过的PendingIntent [英] Cannot Send data Through pendingIntent

查看:111
本文介绍了无法发送数据通过的PendingIntent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用设置我pendingIntent.But收到不能我发送的数据的通知。

I was trying to set a notification using pendingIntent.But I cant recieve the data which I sent.

这些都是codeS

类用于显示通知(正常工作我可以从每一个意图数据)

Class for displaying notification(Working properly I can get every data from intent)

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

     //---get the notification ID for the notification; 
    // passed in by the MainActivity---
    int notifID = getIntent().getExtras().getInt("id");
    String date = getIntent().getExtras().getString("date");
    String time = getIntent().getExtras().getString("time");
    String text = getIntent().getExtras().getString("text");


    //---PendingIntent to launch activity if the user selects 
    // the notification---


    NotificationManager nm = (NotificationManager)
        getSystemService(NOTIFICATION_SERVICE);
    Notification notif = new Notification(
        R.drawable.ic_launcher, 
        text +" "+date+" @ "+time,
        System.currentTimeMillis());
    notif.flags = Notification.FLAG_AUTO_CANCEL;

    CharSequence from = "TODO Note";
    CharSequence message = text;   


    Intent p = new Intent(this,NotifThrow.class);
    p.putExtra("id",notifID);  
    p.putExtra("date",date);

    PendingIntent detailsIntent = 
        PendingIntent.getActivity(this, 0, p, 0);


    notif.setLatestEventInfo(this, from, message, detailsIntent);

    //---100ms delay, vibrate for 250ms, pause for 100 ms and
    // then vibrate for 500ms---
    notif.vibrate = new long[] { 100, 250, 100, 500};        
    nm.notify(notifID, notif);

    //---destroy the activity---
    finish();
}   

}

当我触摸通知这个类(下)应该工作(它的工作原理,但没有从意图数据)

this class (below) should work when I touch on notification(it works but no data from intent)

    public class NotifThrow extends Activity 
    {
TodoDataSource dataSource;
SQLiteDatabase database;

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    int notifID = getIntent().getExtras().getInt("id");
    String dates = getIntent().getExtras().getString("date");

    Log.i("Message From Notification Touch","Id"+notifID);
    dataSource = new TodoDataSource(this);
    dataSource.alarmToggle(notifID);
    Intent intent = new Intent(this,MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    startActivity(intent);

}

编号,日期都显示为空

id ,date are showing null

我究竟做错了什么?
在此先感谢..

what am I doing wrong here ? Thanks in advance..

推荐答案

如果您呼叫已经那么在运行,而不是创建新实例活动的实例,它会调用<一个href=\"http://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29\"相对=nofollow> onNewIntent()。 getIntent()的onCreate 总是返回这是用于发射活动(第一个)。

If the instance of activity you are calling is already running then instead of creating new instance, it will call onNewIntent(). getIntent() from onCreate always returns the Intent which was used for launching Activity (the first one).

这篇关于无法发送数据通过的PendingIntent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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