Onnewintent Is Not Called

onNewIntent not get called

It is because of the onNewIntent is not being called!!!

I put this on where this activity is get called.

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);

then its works like a charm!!.

It is because of calling new activity. And FLAG_ACTIVITY_SINGLE_TOP makes onNewIntent get called. This FLAG_ACTIVITY_SINGLE_TOP will not start a new Activity.

Android - onNewIntent is not called - singletop activities

onNewIntent(Intent intent)

is only called once before the activity is created. After that It will not call untill you destroy and recreate the activity...
Please see the docs, It will more clarify you,
http://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)

Android OnNewIntent not called

Ok got it working soon after posting my question. I think the key difference in our code is that I pass the flag "PendingIntent.FLAG_UPDATE_CURRENT" to the creation/retrieval of the PendingIntent object. This post helped me figure that out.

Notification.Builder mBuilder =
new Notification.Builder(context)
.setSmallIcon(R.drawable.notifyicon)
.setContentTitle(title)
.setContentText(extras.getString("message"))
.setAutoCancel(true)
.setOnlyAlertOnce(false)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setVibrate(new long[] {0,500,250,500});

if(badgeCount > 1)
mBuilder.setNumber(badgeCount);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context, SiteViewActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
resultIntent.putExtra(NOTIFY_INTENT_TYPE_KEY, alertType);

PendingIntent resultPendingIntent = PendingIntent.getActivity(context, alertType, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager notifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notifyMgr.notify(alertType, mBuilder.build());

onNewIntent is not being called

Add FLAG_ACTIVITY_SINGLE_TOP flag to your intent
(see onNewIntent(Intent intent)).

OnNewIntent not called when starting up an Activity through a NFC tag

Try this:

protected void onCreate(Bundle savedInstanceState) {

//Your stuff
Intent intent = getIntent();
handleIntents(intent);
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
handleIntents(intent);
}

private void handleIntents(Intent intent) {
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) {
//stuff
}
}


Related Topics



Leave a reply



Submit