android - OnActivityResult is never called -
i have 2 standalone applications. application , application b. want start activity in application b application , results back. in application b there 1 more activity. b second acitivty result b's first activity. want these result application a. onactivityresult in never called. following code.
application a:
public void onclickbtntoapplicationb(view v) { try { final intent intent = new intent(intent.action_main, null); final componentname cn = new componentname("pakacagename","package.class"); intent.setcomponent(cn); intent.setaction(intent.action_main); intent.addcategory(intent.category_launcher); intent.setflags(intent.flag_activity_new_task); startactivityforresult(intent, request_code); } catch (activitynotfoundexception e) { //handle exception } } public void onactivityresult(int requestcode, int resultcode, intent intent) { switch (requestcode) { case request_code: handleresult(resultcode, intent); break; } } public void handleresult(int resultcode, intent intentresult) { switch (resultcode) { case result_ok: string result = intentresult.getstringextra("result"); // need results application b here.. break; case result_canceled: break; } }
application b activity 1.class:
intent s = new intent(1.this,2.class); startactivityforresult(s, request_code_b); protected void onactivityresult(int requestcode, int resultcode, intent intentresult) { switch(requestcode){ case request_code_b: handleresult(resultcode, intentresult); } } public void handleresult(int resultcode, intent intentresult) { switch (resultcode) { case result_ok: string scanresult = intentresult.getstringextra("result"); intent newintent = new intent(); newintent.putextra("result", scanresult); setresult(activity.result_ok, newintent); finish(); break; case result_canceled: break; }
from documentation:
note method should used intent protocols defined return result. in other protocols (such action_main or action_view), may not result when expect. example, if activity launching uses singletask launch mode, not run in task , receive cancel result.
Comments
Post a Comment