我能够创建推送通知,并将用户发送到我想要的任何活动,但我注意到每当用户登陆该活动时,onCreate 函数都不会被调用。
应该是这样吗?如何设置它以便调用 Activity 的 onCreate?
这是我的活动:
public class QuestionActivity extends BaseListActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
以下是通知的生成方式:
Intent notificationIntent = new Intent(context, MainActivity.class);
if ( notification_type != null && notification_type.equals("question"))
{
notificationIntent = new Intent(context, QuestionActivity.class);
}
else
if ( notification_type != null && notification_type.equals("plan"))
{
notificationIntent = new Intent(context, TopicActivity.class);
}
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Notification notification = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setContentIntent(intent)
.setSmallIcon(icon)
.setLights(Color.YELLOW, 1, 2)
.setAutoCancel(true)
.setSound(defaultSound)
.build();
notificationManager.notify(0, notification);
谢谢!