Android: пакет уведомлений не запускается - PullRequest
0 голосов
/ 15 февраля 2012

У меня есть уведомление, которое должно дать мне некоторые параметры при открытии активности через указанное уведомление.

    private void notify_newOrders(int count) {
    int icon = R.drawable.ic_notification;

    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    CharSequence tickerText = infotext;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);   
    Context context = getApplicationContext();
    CharSequence contentTitle = "Title";
    CharSequence contentText = "Infotext";

    Intent notificationIntent = new Intent(this, TestActivity.class);       
    notificationIntent.putExtra("resuming", "123");
    notificationIntent.setAction("resuming");

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.flags |= Notification.DEFAULT_ALL;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;        

    notification.number = count;

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    mNotificationManager.notify(WORKNOTIFICATION_ID, notification);         

}

В своей деятельности я имею следующее:

    @Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    try{
        super.onCreate(savedInstanceState);         

        setContentView(R.layout.main);
        Bundle extras = getIntent().getExtras();

        if(extras != null)
        {
            Log.d("YAY","got extras");
        }

Проблема в том, что я никогда не получаю никаких дополнений. Я сталкивался с подобными (решенными) проблемами здесь и пытался выяснить, почему они работали, а моя - не оказалась бесполезной. Помогите!

В logCat я получаю их, понятия не имею, актуальны ли они:

INFO/ActivityManager(59): Starting activity: Intent { act=resuming flg=0x24000000 cmp=com.test.test/.TestActivity bnds=[0,101][320,165] (has extras) }
WARN/ActivityManager(59): startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { act=resuming flg=0x24000000 cmp=com.test.test/.TestActivity bnds=[0,101][320,165] (has extras) }

Ответы [ 2 ]

2 голосов
/ 16 февраля 2012

Оказывается, правильно было сделать

@Override 
public void onNewIntent(Intent intent)
0 голосов
/ 15 февраля 2012

Похоже, ваша активность не создана, а возобновлена. Переместите ваш код getExtras из onCreate () в onResume (), это должно работать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...