android - startActivityForResult resultcode always 0 -


i'm trying edited list activity 2 activity 1. here code:

public void listdatasms(arraylist<mysmslog> stringlist) {     bundle bundle = new bundle();     bundle.putparcelablearraylist(number_list, stringlist);     intent = new intent(this, mycommonlistactivity.class);     i.putextra(who_int, sms_log);     i.putextras(bundle);     startactivityforresult(i, sms_log); }  @override protected void onactivityresult(int requestcode, int resultcode, intent data) {     if (requestcode == sms_log) {         if (resultcode == result_ok) {             arraylist<mysmslog> mysmslogs = (data.getparcelablearraylistextra(pick_sms_log));             mainlog.setsmslog(mysmslogs);         }           if (resultcode == result_canceled) {             // if there no result         }     } }  @override public void onbackpressed() {     super.onbackpressed();     intent intent = new intent();     bundle result = new bundle();     switch (who) {         case sms_log:             result.putparcelablearraylist(mainactivity.pick_sms_log, mysmsloglist);             break;     }      setresult(result_ok, intent);     intent.putextras(result); } 

but never setsmslog because resultcode 0. tried android onactivityresult 0 no result. if change condition if (resultcode == result_canceled) {do smth} program ends nullpointerexception.

assuming onbackpressed() code shown above mycommonlistactivity, late call setresult(). @ best, code might work if call super.onbackpressed() last thing, not first. typical solution call setresult() , finish() user taps on in listview or otherwise chooses particular item work with, rather wait until user presses back.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -