Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓Can';t清除或替换额外的_Android_Android Intent_Extra - Fatal编程技术网

Android 安卓Can';t清除或替换额外的

Android 安卓Can';t清除或替换额外的,android,android-intent,extra,Android,Android Intent,Extra,我从通知中删除了午餐活动 Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP ); notificationIntent.putExtra(GCM_EXTRA_ID, id); PendingIntent intent = P

我从通知中删除了午餐活动

Intent notificationIntent = new Intent(context, MainActivity.class); 
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP );
notificationIntent.putExtra(GCM_EXTRA_ID, id);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notificationManager.notify(0, notification); 
如果活动已销毁,则intent将创建新活动并调用此代码中的oncreate activity

Bundle extras = getIntent().getExtras();

if(extras != null){
    if(extras.containsKey(GCMIntentService.GCM_EXTRA_ID))
    {
        int id = extras.getInt(GCMIntentService.GCM_EXTRA_ID);
        Toast.makeText(this, "GCM_EXTRA_ID ACTIVITY ON CREATE:" + Integer.toString(id) , Toast.LENGTH_LONG).show();
        dbClassItem = new DBClass(this);
        db =  dbClassItem.getWritableDatabase();
        DBClass.setLocateValue(db, id);
        db.close();
        getIntent().putExtra(GCMIntentService.GCM_EXTRA_ID, 0);
    }
}
如果我通过后退按钮关闭活动并再次启动活动,应用程序仍然可以看到,该意图具有额外的键
gcminentservice.GCM\u extra\u ID
(这是一个公共静态字符串)

我如何在下一个应用程序启动时清除或替换此额外设置<代码>getIntent().removeExtra(),
getIntent().getExtras().clear(),getIntent().putExtra(gcminentService.GCM_EXTRA_ID,0)
不起作用。我能做什么?活动具有android:launchMode=“singleTop”键。

您可以这样做

       notificationIntent.putExtra(GCM_EXTRA_ID, null);

这个问题是通过在Activity中使用onNewIntent而不是使用onCrete解决的。

但是我需要在OnCreate中清除多余的内容。我将尝试使用“getIntent().putExtra(gcminentservice.GCM_EXTRA_ID,null)”之类的代码。希望它能工作,但我不这么认为。。。