現在我的主要活動有一個鬧鐘,它啓動了一個在狀態欄上啓動通知的類。當我點擊通知時,它會打開我的主要活動,現在我希望它在該活動中打開一個特定的視圖。如何在活動中打開通知視圖?
這是我的通知代碼。
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
int icon = android.R.drawable.stat_notify_chat; // icon from resources
CharSequence tickerText = "TickerText"; // ticker-text
long when = System.currentTimeMillis(); // notification time
CharSequence contentTitle = "My notification"; // message title
CharSequence contentText = "Hello World!"; // message text
//This is the intent to open my main activity when the notification is clicked
final Intent notificationIntent = new Intent(context, mainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(notifID, notification);
這是我的主要活動使用的佈局中的按鈕,它打開視圖我希望打開通知(圖形視圖)。
<Button
android:id="@+id/graphsButton"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="@id/reviewButton"
android:layout_toRightOf="@id/medicineButton"
android:onClick="openGraphs"
android:text="Graphs" />
當你點擊按鈕。它在主類中執行以下方法。
public void openGraphs(View v) {
canExit = false;
setContentView(R.layout.graphs);
}
所以基本上,我得到通知打開應用程序並啓動主要活動,但我希望它直接啓動圖形視圖。
任何人都可以幫助我嗎?