带有旧的extra和onCreate()的PendingIntent不要求singleTask活动

时间:2018-12-26 17:47:44

标签: android android-pendingintent

当我在意图中设置标志FLAG_ACTIVITY_NEW_TASK时,未在新任务中创建我的单一任务活动,也未调用onCreate。然后创建ID为0和PendingIntent.FLAG_CANCEL_CURRENT的Pending Intent。我能做什么?

Intent notificationIntent = new Intent(getApplicationContext(), CommentPhotoActivity.class);

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
notificationIntent.putExtra("posteid", pId);

PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

NotificationCompat.Builder notificationBuilder = null;
//Preciser que La notif n'a pas été ouverte
//  session.createOpenNotifCmt(false);
if(pathImg.equals("")) {
      //  notificationBuilder = new NotificationCompat.Builder(getApplicationContext()).setContentTitle("Commentaire: " + emeteur).setSmallIcon(R.drawable.ic_launcher).setContentIntent(contentIntent).setContentText(cmt).setDeleteIntent(mBroadcastIntentController);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
           notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), "my_channel_01");
           notificationBuilder.setContentTitle("Commentaire: " + emeteur).setSmallIcon(R.drawable.ic_launcher).setContentIntent(contentIntent).setContentText(cmt);//.setDeleteIntent(mBroadcastIntentController);
    } else {
           notificationBuilder = new NotificationCompat.Builder(getApplicationContext()).setContentTitle("Commentaire: " + emeteur).setSmallIcon(R.drawable.ic_launcher).setContentIntent(contentIntent).setContentText(cmt);
    }
}

清单:

 <activity
        android:name=".Activities.CommentPhotoActivity"
        android:label="@string/title_activity_comment_photo"
        android:screenOrientation="portrait"
        android:launchMode="singleTask"
        android:theme="@style/CustomActionBarTheme">

    </activity>

    <service
        android:name=".Services.SocketService"
        android:enabled="true"
        android:exported="true" />

当我单击通知并打开活动时,我需要更改讨论(所有讨论都具有相同的活动)。为此,您必须经历onCreate。

CommentActivity

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_comment_photo);

    if (BuildConfig.DEBUG)
        Log.v(TAG5,"onCreate");

     data = getIntent();

    mGroupManager = new GroupeManager(this);
    postemanager = new PosteManager(this);
    manager = new CommentManager(this);
    groupemanager = new GroupeManager(this);
    mixpanel = MixpanelAPI.getInstance(this, projectToken);
    session = new SessionManager(this);

    if (BuildConfig.DEBUG)
        Log.v(PosteAdapter.TAG1, "go discussion: ParcelableExtra" + data.getParcelableExtra("yuyu"));
    // Determiner la provenance de l intent pour extraire les données
    if (data.getParcelableExtra("yuyu") != null) {
        p = postemanager.getPostFromPostEmmetIdNew(((Poste) data.getParcelableExtra("yuyu")).getIdpostemet());
        poste_id = p.getId();
        if (BuildConfig.DEBUG)
            Log.v(PosteAdapter.TAG1, "go discussion: id=" + p.getId() + " Txt=" + p.getTx() + "IdPostEmet" + p.getIdpostemet());

        if (BuildConfig.DEBUG) {
            Log.v(TAG6, "POST"+p.getTx()+"POST STATE READ: " + p.getVisited());
        }
    } else {
        //Notif Open
    //    session.createOpenNotifCmt(true);
        poste_id = data.getIntExtra("posteid", 0);
        if (BuildConfig.DEBUG) {
            Log.v(SocketService.TAG2, "2: posteid" + data.getIntExtra("posteid", 0));
        }
        p = postemanager.getPost(poste_id);
    }


      ....................

    contactmanager = new ContactManager(this);
    manager = new CommentManager(this);
    allComments = manager.getAllComments(poste_id);
    adapter = new CommentAdapter(this, allComments);

    listCmtView.setLayoutManager(new LinearLayoutManager(this));
    listCmtView.setAdapter(adapter);
    listCmtView.setItemViewCacheSize(10);
    listCmtView.setDrawingCacheEnabled(true);
    listCmtView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

    listCmtView.smoothScrollToPosition(0);

    }

0 个答案:

没有答案