我有以下代码,假设在通知期间初始化一个新活动,它位于服务类中
Intent push = new Intent();
push.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
push.setClass( context, MyActivity.class );
PendingIntent pi = PendingIntent.getActivity( context, 0, push, PendingIntent.FLAG_ONE_SHOT );
long[] vibraPattern = {0, 500, 250, 500 };
Notification noti = new Notification.Builder( getApplicationContext() )
.setVibrate( vibraPattern )
.setDefaults( Notification.DEFAULT_SOUND )
.setFullScreenIntent( pi , true )
.setContentIntent( pi )
.getNotification();
notifMng.notify( 0 , noti );
声音和振动很好,所以通知成功通知,但是 MyActivity 从未创建,即使它是此通知的 FullScreenIntent。