android - Notification not always starting the Activity -
per title, doesn't start activity. there's no error in output log, says
06-01 16:46:36.924: i/activitymanager(370): start u0 {flg=0x10000000 cmp=com.myapp/md527315440e30c82eb86ffbe7caee6cb98.myview bnds=[96,712][1056,840] (has extras)} pid -1
what mean "not always" this:
- i start app, shows main screen. notification received, tap on notification, activity run. app navigates different activity, , activity closed (finish() called).
- next, tap on button until app closed. notification received, tap on notification, activity run. app navigates different activity, , activity closed (finish() called).
- next, keeping app in same state (no navigation). notification received, tap on notification, activity not run.
here's code adding notification:
void createnotification (context context, pushnotification pn) { var builder = new notificationcompat.builder (context) .setcontenttitle (pn.title) .setcontenttext (pn.body) .setsmallicon (resource.drawable.launcher) .setlargeicon (android.graphics.bitmapfactory.decoderesource (context.resources, resource.drawable.launcher)) .setsound (android.provider.settings.system.defaultnotificationuri) .setautocancel (true); android.support.v4.app.taskstackbuilder stackbuilder = android.support.v4.app.taskstackbuilder.create(context); stackbuilder.addparentstack(java.lang.class.fromtype(typeof(loginview))); stackbuilder.addnextintent(getintent()); pendingintent resultpendingintent = stackbuilder.getpendingintent(0, (int)pendingintentflags.updatecurrent); builder.setcontentintent(resultpendingintent); var notificationmanager = context.getsystemservice (context.notificationservice) notificationmanager; notificationmanager.notify(1, builder.build()); } static intent getintent () { // returns intent } i saw other questions same issue no solution works. if can give hints or ideas why might not work.
check out "setting regular activity pendingintent" section of android notifications. not following guidelines laid out in example. particularly, don't following:
create stack based on intent starts activity: create intent start activity. create stack builder calling taskstackbuilder.create(). add stack stack builder calling addparentstack(). each activity in hierarchy you've defined in manifest, stack contains intent object starts activity. method adds flags start stack in fresh task. note: although argument addparentstack() reference started activity, method call doesn't add intent starts activity. instead, that's taken care of in next step.
add intent starts activity notification, calling addnextintent(). pass intent created in first step argument addnextintent(). if need to, add arguments intent objects on stack calling taskstackbuilder.editintentat(). necessary ensure target activity displays meaningful data when user navigates using back. pendingintent stack calling getpendingintent(). can use pendingintent argument setcontentintent().
sorry formatting. i'm unsure how preserve original site.
Comments
Post a Comment