Intent from notification isn't passed to target activity in Android -
in app have starting activity starts/restore app's activities , pass intent extras if there any:
manifest:
<activity android:name=".startactivity" android:theme="@style/theme.appcompat.light.noactionbar.fullscreen" android:screenorientation="sensorlandscape"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity>
code:
public class startactivity extends appcompatactivity { @override protected void oncreate(@nullable bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_preloader); string id=getintent().getstringextra("id"); log.d("push~","start activity oncreate:"+id); intent = new intent(getintent()); openlastactivity(i); finish(); } @override protected void onnewintent(intent intent) { string id=intent.getstringextra("id"); log.d("push~","start activity new intent:"+id); openlastactivity(intent); super.onnewintent(intent); } private void openlastactivity(intent i){ i.setflags(intent.flag_activity_clear_top|intent.flag_activity_single_top); if(gameactivity._this!=null) { i.setclass(this,gameactivity.class); startactivity(i); } else { i.setclass(this,selectoractivity.class); startactivity(i); } } }
also app has service generates notifications following content intent:
intent notificationintent= new intent(context, startactivity.class); notificationintent.putextra("id",id); pendingintent contentintent = pendingintent.getactivity(context, 0, notificationintent, pendingintent.flag_update_current); builder.setcontentintent(contentintent);
i expect id string passed last active activity.
problem when run app via notification tap starts app , pass id expected if there notification(when i'm still in app) neither oncreate nor onnewintent method of startactivity
called therefore no data passed main activities.
upd:don't know why android:launchmode="singletask"
startactivity
solved problem.now intents receiving in oncreate
don't know why android:launchmode="singletask"
startactivity
solved problem.now intents receiving in oncreate
Comments
Post a Comment