【发布时间】:2012-12-11 15:03:37
【问题描述】:
此代码创建一个通知。如果点击它,则运行当前应用程序(intent 是在Entry 中创建的,这是我唯一的Activity),一个Android 开发者博客的略微修改版本:
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 和@987654328 中进行更改@,我仍然没有可用的结果。是否有可能以某种方式调用Entry 中的一个方法(我的主要Activity,其中创建了Intent),或者当我单击我新创建的Notification 时捕获任何传出或传入的Intents?
PS。如果这是一个重复的线程,我很抱歉,所以现在很慢,我无法正确搜索。
【问题讨论】:
标签: android android-intent android-activity android-notifications