问题描述
您好,我是新来的Android系统。
我实现一个code。与通知功能。在这里,我有两个活动,我的应用程序这些都是ActivityA和ActivityB。
我想从通知开始ActivityB,我需要发送一些标志或某些价值的ActivityB。我怎样才能发送数据,如int值或标志使用上点击通知,称为活动。问题是,当我启动从启动器图标的活动首先它会叫ActivityA并从ActivityA我传递一些价值ActivityB。
但是,当我从启动通知ActivityB我续发任何值的活动,这样它给部队密切。
Hi i am new to android. I am implementing a code with notification functionality. Here i have two activities in my application those are ActivityA, and ActivityB.I want to start ActivityB from notification and i need to send some flag or some value to the ActivityB. How can i send the data like int value or flag to that called activity using notification on click. The problem is when i am launching activity from launcher icon first it will called ActivityA and from that ActivityA i am passing some value to ActivityB.But when i am launching ActivityB from notification i con't send any values to that activity so it is giving force close.
要我用这code从电话通知活动
To call activity from notification i am using this code
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.android,"New Alert, Click Me!",System.currentTimeMillis());
Context context = getApplicationContext();
CharSequence contentTitle = "Notification Details...";
CharSequence contentText = "Browse Android Official Site by clicking me";
Intent notifyIntent = new Intent(Intent.ACTION_MAIN);
notifyIntent.setComponent(new ComponentName("mypackage","mypackage.ActivityB"));
PendingIntent intent = PendingIntent.getActivity(SimpleNotification.this, 0,notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
请告诉我如何从通知发送值叫做活动。
Please advise me how can i send values from notification to called activity.
推荐答案
您必须设置在ActivityB notifyIntent
you must set your ActivityB in notifyIntent
Intent notifyIntent = new Intent(this, ActivityB.class); // 'this' - Context object
有关发送值使用临时演员
例如:
For sending values use extrasfor example:
intent.putExtra("yourTag", yourVariable);
这篇关于如何写的onclick通知项目llistener在android系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!