Android getIntent() returns current activity -
i have question getintent(); makes activity(activity a) call activity(activity b). it's different package name. problem when use getintent(), return of getintent activity b. intent.getextras() null. problem? think getintent() should return activity a. it's work start activity b.
activity a
intent intent = new intent(); intent.setclassname(b package, b activity); intent.putextra("test", test); startactivityforresult(intent, request_ok);
activity b
intent intent = getintent(); log.d(tag, "" +getintent()); if(intent.getextras() != null){ string name = intent.getstringextra("test"); }
thanks.
activity a as
public void testintentcall(view view) { intent intent = new intent(this,testintent.class); intent.putextra("test","test"); startactivity(intent); }
with activity b
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); log.d("intent test","intent passed=>" + getintent().tostring()); intent intent = getintent(); if(intent.getextras() != null) { log.d("intent test", "intent extras=>" +intent.getextras().tostring()); log.d("intent test", "intent test =>" + intent.getstringextra("test")); } finish(); }
results in :-
06-02 13:45:40.615 11027-11027/mike092015.app001 d/intent test: intent passed=>intent { cmp=mike092015.app001/.testintent (has extras) } 06-02 13:48:00.531 11027-11027/mike092015.app001 d/intent test: intent extras=>bundle[mparcelleddata.datasize=40] 06-02 13:48:00.531 11027-11027/mike092015.app001 d/intent test: intent test =>test
so issue appears either setclassname
or startactivityforresult
.
tested using startactivityforresult(intent,0)
or 1 runs ok same results. issue appears setclassname
.
i'm wondering if issue activity b, due class component invoked, based upon b package, b activity
being set/passed, starting activity b activity b , it's parent might itself. perhaps log contains 2 messages , perhaps first shows caller activity.
what b package , b activity , crucial in determining issue.