简体   繁体   English

Android - 点击通知打开我的主要活动,如何让它打开其他东西

[英]Android - Click on notification opens up my main activity, how do I make it open up something else

I have a simple app that shows android notifications depending to one of three buttons you press. 我有一个简单的应用程序,根据您按下的三个按钮之一显示Android通知。

Dog, Cat, or Mouse 狗,猫或老鼠

If you press dog then a notification that says "Dog" shows. 如果您按下狗,则显示“狗”显示的通知。 If you press cat then a notification that says "Cat" shows. 如果按cat,则显示“Cat”的通知。 If you press mouse then a notification that says "Mouse" shows. 如果按鼠标,则显示“鼠标”显示的通知。

When you click the notification it just takes me to my main activity (with the three buttons again). 当您单击通知时,它会将我带到我的主要活动(再次使用三个按钮)。 I would like it to take me to a separate activity, that will read what notification was clicked, and set it the text from the notification as a textView. 我希望它能够将我带到一个单独的活动,该活动将读取所点击的通知,并将通知中的文本设置为textView。

Any ideas on how to do this? 关于如何做到这一点的任何想法?

NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle("My notification")
        .setContentText("Hello World!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, ResultActivity.class);

// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(
            0,
            PendingIntent.FLAG_UPDATE_CURRENT
        );
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());

Source: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Actions 资料来源: http//developer.android.com/guide/topics/ui/notifiers/notifications.html#Actions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android中单击通知打开相同的活动? - How to open same activity on click of notification in android? 如何直接打开非主要活动的Android应用程序,然后再转到主要活动? - How do I open an Android app straight to an activity that is not the main activity and later move to the main activity? 如何从活动中打开android.support.v4.app.Fragment - how do i open up android.support.v4.app.Fragment from an activity 当我收到通知时如何进行弹出活动? - How can i make a pop up activity when i got a notification? 单击复选框时如何打开一个单独的可编辑框架? - How do I make so when I click my checkbox, a separate and editable frame opens? Android-为什么在点击通知后“活动”处于打开状态? - Android - Why Activity is Open after click notification? 如何在点击通知时打开活动 - How can i open Activity when notification click 你如何在 android 中创建一个按钮来打开一个新的活动,这个活动不仅仅是一个默认活动,它是一个自定义活动 - How do you make a button in android that opens a new activity and this activity is not just a default activity its a custom one Android通知会在现有活动中打开 - Android Notification Opens On Existing Activity 清理Android主要活动代码 - Cleaning up Android Main Activity Code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM