twitter4j - Android data is lost onCreate() after startActivity() for callback -


i have android app connects twitter via twitter4j. in activity there share button , textview. flow below;

  1. user opens activity starting oncreate() populates textview
  2. user clicks "share"
  3. twitter activity started oauth, user types account credentials , gives permission app
  4. user gets redirected activity again starting oncreate()

my problem value of textview lost after second oncreate().

- oncreate() . . point = getintent().getextras().getint("point"); . .  - sharebutton.onclick() . .               thread thread = new thread(new runnable() { @override public void run() { intent intent = new intent(intent.action_view, uri.parse(requesttoken.getauthenticationurl()));// open twitter authentication  intent .putextra("point", point); startactivityforresult(intent , 1); } }); thread.start(); . . 

things have tried far;

  • using startactivityforresult() instead of startactivity()
  • using intent.putextra() before startactivity() , calling getintent().getextras().getint("point") in oncreate() there no such data
  • using onsaveinstancestate() , onrestoreinstancestate() savedinstancestate null

please tell me how can persist data after twitter callback. can use database or shared preferences or there way?

thanks in advance.

edit:

when program goes twitter , come back, starts again oncreate() when orientation changes. when orientation changes "bundle savedinstancestate" has value in case has no value.

how can savedinstancestate -which set before manually- in second run of oncreate() after return of twitter callback?

edit 2:

some people in site weird. posted answer below new post deleted claiming "the new post should include answer". know what, that post has real answer. don't act without reading of it. i'm writing below edit.

thank answer (@rod_torres). have tried solution (with , without i.addflags(intent.flag_activity_clear_top)) , in both cases couldn't achieve. life cycle when set singletop below;

oncreate() -> twitter -> oncreate()

onnewintent() wasn't called after come twitter. activity recreated new instance can go back button in order above.

i tried singletask , worked (the answer of question this, deleted post without reading part). didn't create new instance of activity , onnewintent() called . when click button, got redirected previous activity of app, not task of browser (twitter) although twitter previous activity. flow like;

oncreate() -> twitter -> oncreate(with bundles) -> onnewintent()

activity -> activity b -> twitter -> activity b (same previous)

when go activity b;

activity -> browser

it seems singletask mode brought app's task foreground activities in , brought other app's (browser) task stack. right?

but still couldn't understand why solution didn't worked me. have read lot of documentation , think should have been worked.

also, i'm not sure if should use singletask. there wrong haven't take account yet, disadvantages?

as point out in edit activity recreated. make app not recreate activity add in manifest parameter launchmode value "singletop" activity using twitter4j

<activity         android:name=".secondactivity"         android:label="@string/title_activity_second"         android:launchmode="singletop"> 

also, when call activity add flag flag_activity_clear_top:

intent = new intent(this, secondactivity.class); i.putextra("string","second activity biches"); i.addflags(intent.flag_activity_clear_top); startactivity(i);  

for more information:

http://www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode https://developer.android.com/reference/android/content/intent.html#flag_activity_clear_top


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -