首先认识一下安卓newIntent方法的使用:
newIntent方法的使用在于如果activity已经开启了,并设置了启动模式为: android:launchMode="singleTask"的时候,当再次使用intent来启动这个activtiy的时候就会进入这个方法里面onNewIntent(Intent intent) ,当在接受通知栏的函数里面,就可以传递参数,在该activity的onnewIntent进行判断处理,如果Activity被关闭了,将会重新调用onCreate方法,所以安全起见,在onCreate中也需要加入判断指定需要显示的界面,如下图:
关于onnewintent的部分解释如下:
然后需要自定义一个广播接收器用于接收通知栏信息
<!-- User defined. 用户自定义的广播接收器 --> <receiver android:name=".notificationbar.MessageReceiver" android:enabled="true"> <intent-filter> <!-- Required 用户注册SDK的intent --> <action android:name="cn.jpush.android.intent.REGISTRATION" /> <!-- Required 用户接收SDK消息的intent --> <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <!-- Required 用户接收SDK通知栏信息的intent --> <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <!-- Required 用户打开自定义通知栏的intent --> <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!-- 接收网络变化 连接/断开 since 1.6.3 --> <action android:name="cn.jpush.android.intent.CONNECTION" /> <category android:name="hz.resfine.helpme_repair" /> </intent-filter> </receiver>
/**