通知中的PendingIntent不叫我的活动第二次 [英] PendingIntent of Notification don't call my Activity second time

查看:89
本文介绍了通知中的PendingIntent不叫我的活动第二次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望收到推送通知(C2DM)接收显示通知。该通知开始,蒙山的PendingIntent,即显示一个弹出一个活动。该弹出的确定按钮,点击启动时,我的应用程序。

I hope that receiving a push-notification (c2dm) reception display Notification. This Notification start, whith PendingIntent, an Activity that display a pop-up. This popup launch my application when clicking on the "ok" button.

下面是在接收推通知执行code:

Here is the code executed at the reception of push-notification :

private void dealMessage(Context context, Intent intent)
{       
    try
    {
        String message = intent.getExtras().getString("message");

        Log.v("testc2dm","message :     [" + message + "]");

        //create bean of my Notification
        NotificationPush notif = new NotificationPush();
        notif.init((JSONObject)JSONValue.parse(message));

        //create PendingIntent
        Intent intentDialog = new Intent(context, DialogActivity.class);
        intentDialog.putExtra("notif", notif);
        int requestCode= (int) System.currentTimeMillis();
        PendingIntent pi = PendingIntent.getActivity(context, requestCode, intentDialog, PendingIntent.FLAG_ONE_SHOT);

        //Create the Notification
        Notification n = new Notification();
        n.flags |= Notification.FLAG_SHOW_LIGHTS; // allume l'écran
        n.flags |= Notification.FLAG_AUTO_CANCEL; // fait disparaitre automatiquemet la notif apres un clic dessus
        n.defaults = Notification.DEFAULT_ALL;
        n.icon = R.drawable.icon;
        n.when = System.currentTimeMillis();
        n.setLatestEventInfo(context, "Mon titre", notif.getTitre(), pi);

        //add my Notification
        NotificationManager notificationManager = (NotificationManager)context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(ID_NOTIFICATION, n);
    }
    catch(Exception e)
    {
        Log.e("testc2dm","error :       [" + e.getMessage() + "]");
        e.printStackTrace();
    }
}

这是我的活动,显示弹出,并开始我的应用程序:

this is my activity that displays popup and start my application :

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

    Log.v("testc2dm","DialogActivity oncreate()");

    //recovery of my bean Notification
    Intent intentParam = getIntent();
    NotificationPush notif = (NotificationPush)intentParam.getSerializableExtra("notif");

    if(notif != null)
    {           
        Log.v("testc2dm","notif => titre [" + notif.getTitre() + "] -- msg [" + notif.getMessage() + "] -- type [" + notif.getType() + "]");

        //display popup
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(notif.getMessage());
        builder.setTitle(notif.getTitre());
        builder.setCancelable(false);
        builder.setNegativeButton("Ok", new DialogInterface.OnClickListener() 
        {
            public void onClick(DialogInterface dialog, int id) 
            {
                if(!TestC2DMActivity.appIsRunning)
                {
                    //launch first Activity of my application
                    Intent intent = new Intent(DialogActivity.this, TestC2DMActivity.class);
                    startActivity(intent);
                }
            }
        });
        builder.show();
    }
}

我的问题是:如果我的应用程序将通过接收推送(C2DM>的通知>的PendingIntent> DialogActivity> TestC2DMActivity),然后接收下一个推,通知会出现罚款,但点击通知不会推出DialogActivity启动。而当应用程序正常启动(应用程序的图标),然后一切工作正常。

My problem is : if my application will be started by receiving a push (c2dm > Notification > PendingIntent > DialogActivity > TestC2DMActivity) then receive the next push, the Notification will appear fine, but clicking on the Notification will not launch DialogActivity. Whereas when the application is started normally (icon of the app) then everything works fine.

我觉得如果我的申请是由我的PendingIntent启动,那么这个的PendingIntent不再希望推出DialogActivity。为什么?

I feel that if my application is started by my PendingIntent, then this PendingIntent no longer want launch DialogActivity .. Why??

真的感谢您的帮助和抱歉,我的英语不好..

really thanks for your help and sorry for my bad english..

推荐答案

我有解决方案:

intentDialog.setAction("" + Math.random());

<一个href=\"http://stackoverflow.com/questions/2882459/getextra-from-intent-launched-from-a-pendingintent\">getExtra从意向从的PendingIntent启动

getExtra from Intent launched from a pendingIntent

谢谢你的好意

这篇关于通知中的PendingIntent不叫我的活动第二次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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