这段代码创建了一个通知。如果你点击它,当前应用程序就会启动(该意图是在Entry
中创建的,它是我唯一的Activity
),这是安卓开发者博客稍微修改过的版本:
private void makeIntent() {
NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.prev, "Status message!", System.currentTimeMillis());
Intent intent = new Intent(this, Entry.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
note.setLatestEventInfo(this, "New Email", "Unread Conversation", pi);
note.flags |= Notification.FLAG_AUTO_CANCEL;
mgr.notify(NOTIFY_ME_ID, note);
}
但我不想启动任何活动,只是在当前活动中运行一个方法。根据我目前所读的内容,我猜我必须使用像startActivityForResult()
这样的方法,使用intent-filters
并实现onActivityResult()
,但在尝试各种更改Intent
和PendingIntent
后,我仍然没有可用的结果。是否可能以某种方式仅调用Entry
中的方法(我的主要Activity
,其中创建了Intent
),或者在点击我的新建Notification
时捕获任何传出或传入的Intents
?
PS:如果这是重复的帖子,请见谅,SO现在相当缓慢,我无法正常搜索。