应用程序在重定向到活动后关闭当点击推送通知后再次按下

时间:2016-05-06 11:58:49

标签: android push-notification android-notifications

我遇到了大麻烦,情节是我有一个应用程序,所以当我打开它时,后面的堆栈活动就像活动A是飞溅然后移动到B然后C然后是D.所以当我按下后退按钮活动发射的顺序是DCBA。但是当点击推送通知并且点击它之后它打开活动D.现在当我按下后退按钮应用程序关闭而应用程序的行为应该是它应该重定向回活动(让我们说活动B)这是在未单击通知时运行。 在此先感谢,我很感激您的建议。

更新这是我的消息处理程序

 @Override
    public void onMessageReceived(String from, Bundle data) {
        String bundledata = data.getString("data");
        String message=data.getString("message");
        sendNotification(message,bundledata);
        NOTIFICATION_ID++;
    }

    private void sendNotification(String message,String bundledata) {

        intialization();
        setNotification(message,bundledata);

    }


    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    private void setNotification(String message,String bundledata)
    {

        NotificationManager  mNotificationManager = (NotificationManager)
                this.getSystemService(Context.NOTIFICATION_SERVICE);


        stackBuilder.addParentStack(GcmNotificationRedirect.class);
        Intent notificationIntent = new Intent(this, GcmNotificationRedirect.class);
        notificationIntent.putExtra("pushMessage", message);
        notificationIntent.putExtra("bundleData",bundledata);
        notificationIntent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
        stackBuilder.addNextIntent(notificationIntent);


        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent( NOTIFICATION_ID,
                        PendingIntent.FLAG_CANCEL_CURRENT
                );


       // NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setContentTitle(title)
                        .setPriority(Notification.PRIORITY_MAX)
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(message))
                        .setContentText(message)
                        .setNumber(pushNumber);


            mBuilder.setColor(this.getResources().getColor(R.color.theme_color));
            mBuilder.setSmallIcon(R.drawable.app_icon);
            mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), getNotificationIcon()));


        mBuilder.setContentIntent(resultPendingIntent);
        mBuilder.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
        Notification notification = mBuilder.build();
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        mNotificationManager.notify(NOTIFICATION_ID, notification);

    }

将消息重定向到不同活动的活动

public class GcmNotificationRedirect extends Activity {

    String pushMessage;
    String bundleData;
    Push_Notification_Pojo pojo;
    public static final String PRODUCT_PAGE="PRODUCT_PAGE";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        pushRedirect();

    }

    private void pushRedirect()
    {
        pushMessage = getIntent().getStringExtra("pushMessage");
        bundleData = getIntent().getStringExtra("bundleData");

/*
        Intent intent1 = new Intent(GcmNotificationRedirect.this,NavigationController.class);
        intent1.putExtra("pushMessage", pushMessage);
        intent1.putExtra("bundleData",bundleData);
        startActivity(intent1);*/

        parsePushNotifiactionJson(pushMessage,bundleData);
        finish();

    }

    private void parsePushNotifiactionJson(String pushMessage, String bundleJSONData){
        Intent pushNotiInetent = null;

        if(pushMessage!=null && bundleJSONData!=null) {
            try {

                JSONObject jsonObject = new JSONObject(bundleJSONData);

                if (jsonObject.getString("type").equals(PRODUCT_PAGE)) {

                    pojo = new Push_Notification_Pojo(jsonObject.getString("productId"), jsonObject.getString("type"),pushMessage);
                    pushNotiInetent = new Intent(this, ProductDetail.class);
                    pushNotiInetent.putExtra("push_notification_pojo", pojo);
                    startActivity(pushNotiInetent);
                }

                else
                {
                    pojo = new Push_Notification_Pojo(jsonObject.getString("promotionId"), jsonObject.getString("type"), pushMessage, true);

                    if(pojo!=null)
                    {
                        NavigationController.menuRequired=NavigationController.PERMOTIONAL_OFFERS;
                        pushNotiInetent = new Intent(this, NavigationController.class);
                        pushNotiInetent.putExtra("pushMessage", pushMessage);
                        pushNotiInetent.putExtra("bundleData",bundleData);
                        startActivity(pushNotiInetent);
                    }
                }

               // pushNotiInetent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
            }
            catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }


}

0 个答案:

没有答案