开发者

Android Notification message (doesn't) switch from activity

开发者 https://www.devze.com 2023-02-01 12:06 出处:网络
I was trying to switch from tabview (those took about 1/3rd of a small screen) to fullscreens selectable via notification messages.

I was trying to switch from tabview (those took about 1/3rd of a small screen) to fullscreens selectable via notification messages.

So far so good, everything done following the instructions on many howto's its all working like a charm. (that is on the sdk emulator)

now i've transfered the app to my actual android telephone and now it doesn't switch the screens anymore via the notifications. it ALWAYS opens the MainActivity.

private void DroiDCNotification(int NotificationID, CharSequence tickerText, CharSequence contentTitle, CharSequence contentText) {
    //throw new UnsupportedOperationException("Not yet implemented");
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    int icon = R.drawable.dro开发者_开发问答idc_icon;        // icon from resources
    long when = System.currentTimeMillis();         // notification time
    Context context = getApplicationContext();      // application Context
    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 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(NotificationID, notification);
}

So how can i make the notification called by a specific Activity open that specified Activity?


I was trying to switch from tabview (those took about 1/3rd of a small screen) to fullscreens selectable via notification messages.

I have no idea why you think that this is a good idea. Notifications are not designed for this role. Please use an options menu.

So how can i make the notification called by a specific Activity open that specified Activity?

It is going to execute the PendingIntent. Your PendingIntent wraps an Intent identifying MainActivity.class. If you do want it to use MainActivity.class, change MyActivity.class to whatever class you wish.


Hi Just use this twolines in yr activity

Intent notificationIntent = new Intent(context, SamplePushActivity.class);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
0

精彩评论

暂无评论...
验证码 换一张
取 消