美文网首页
android startActivityForResult小知

android startActivityForResult小知

作者: 临界最终散射面 | 来源:发表于2020-05-02 10:53 被阅读0次

    当Intent的flag被设置为FLAG_ACTIVITY_NEW_TASK时,回调会失效,因为新的activity与老的activity不在同一个task中,不存在父子关系。

    此种情况onActivityResult方法会被立刻回调resultCode为取消码。

    /** * Launch an activity for which you would like a result when it finished. * When this activity exits, your * onActivityResult() method will be called with the given requestCode. * Using a negative requestCode is the same as calling * {@link #startActivity} (the activity is not launched as a sub-activity). * * <p>Note that this method should only be used with Intent protocols * that are defined to return a result. In other protocols (such as * {@link Intent#ACTION_MAIN} or {@link Intent#ACTION_VIEW}), you may * not get the result when you expect. For example, if the activity you * are launching uses {@link Intent#FLAG_ACTIVITY_NEW_TASK}, it will not * run in your task and thus you will immediately receive a cancel result. * * <p>As a special case, if you call startActivityForResult() with a requestCode * >= 0 during the initial onCreate(Bundle savedInstanceState)/onResume() of your * activity, then your window will not be displayed until a result is * returned back from the started activity. This is to avoid visible * flickering when redirecting to another activity. * * <p>This method throws {@link android.content.ActivityNotFoundException} * if there was no Activity found to run the given Intent. * * @param intent The intent to start. * @param requestCode If >= 0, this code will be returned in * onActivityResult() when the activity exits. * @param options Additional options for how the Activity should be started. * See {@link android.content.Context#startActivity(Intent, Bundle)} * Context.startActivity(Intent, Bundle)} for more details. * * @throws android.content.ActivityNotFoundException * * @see #startActivity */

    相关文章

      网友评论

          本文标题:android startActivityForResult小知

          本文链接:https://www.haomeiwen.com/subject/cmoqghtx.html