美文网首页
Receiver中启动两次Activity

Receiver中启动两次Activity

作者: feng_wy | 来源:发表于2019-08-27 14:29 被阅读0次

    1.广播接收者会启动两个CameaList

    public class EzvizBroadcastReceiver extends BroadcastReceiver {
        private static final String TAG = "EzvizBroadcastReceiver";
        Intent toIntent =null;
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(Constant.OAUTH_SUCCESS_ACTION)) {
                Log. e(TAG, "onReceive: OAUTH_SUCCESS_ACTION");
                toIntent = new Intent(context, CameraList.class);
                toIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                EZAccessToken token = MyApplication.getOpenSDK().getEZAccessToken();
                context.startActivity(toIntent);
            }
        }
    }
    

    2.解决办法为

    1.intent添加flags
    toIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    2.manifest 文件里面添加启动模式
    <activity android:name="com.video.camera_list.CameraList" android:launchMode="singleTask" />
    
    
    

    相关文章

      网友评论

          本文标题:Receiver中启动两次Activity

          本文链接:https://www.haomeiwen.com/subject/rkreectx.html