• 关于启动模式中的问题


    startActivityForResult的问题

    A,B,C的启动模式都是默认的

    Activity A 启动了Activity B,Activity B又启动了C,A-->B-->C, 这种情况下,A启动B要求B返回result给A

        

       如上图所示,Intent设置了Intent.FLAG_ACTIVITY_FORWARD_RESULT标志,那么此时将会交由C向A setResult。为了避免冲突,B启动C时不得指定resultRecord>=0。

            ActivityRecord sourceRecord = null;
            ActivityRecord resultRecord = null;
            if (resultTo != null) {
                int index = indexOfTokenLocked(resultTo);
                if (DEBUG_RESULTS) Slog.v(
                    TAG, "Sending result to " + resultTo + " (index " + index + ")");
                if (index >= 0) {
                    sourceRecord = (ActivityRecord)mHistory.get(index);
                    if (requestCode >= 0 && !sourceRecord.finishing) {
                        resultRecord = sourceRecord;
                    }
                }
            }
    
            int launchFlags = intent.getFlags();
    
            if ((launchFlags&Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0
                    && sourceRecord != null) {
                // Transfer the result target from the source activity to the new
                // one being started, including any failures.
                if (requestCode >= 0) {
                    return START_FORWARD_AND_REQUEST_CONFLICT;
                }
                resultRecord = sourceRecord.resultTo;
                resultWho = sourceRecord.resultWho;
                requestCode = sourceRecord.requestCode;
                sourceRecord.resultTo = null;
                if (resultRecord != null) {
                    resultRecord.removeResultsLocked(
                        sourceRecord, resultWho, requestCode);
                }

    A-->B

    如果A和B不在同一个task中,那么startActivityForResult將返回RESULT_CANCELED

     如果启动的activity需要新的task,那么新启动的activity将会与其caller断开依赖关系,这个关系主要是指result反馈,A-->B,如果A是通过startActivityForResult()请求启动的,并且requestCode >=0,那么如果B是在新的task中,那么B在finish的时候将不再向A反馈result,而是在启动过程中就会向A反馈一个RESULT_CANCELED。

            if (r.resultTo != null && (launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
                // For whatever reason this activity is being launched into a new
                // task...  yet the caller has requested a result back.  Well, that
                // is pretty messed up, so instead immediately send back a cancel
                // and let the new task continue launched as normal without a
                // dependency on its originator.
                Slog.w(TAG, "Activity is launching as a new task, so cancelling activity result.");
                sendActivityResultLocked(-1,
                        r.resultTo, r.resultWho, r.requestCode,
                    Activity.RESULT_CANCELED, null);
                r.resultTo = null;
            }

    摘自http://blog.csdn.net/windskier/article/details/7096521

  • 相关阅读:
    2.8Java专项测试复盘
    我的第一篇博客
    VS2010调试汇编
    socket学习
    DLL 共享数据学习
    PE学习
    char*,const char*和string的相互转换 + 三种版本字符串
    unresolved external symbol “symbol”(不确定的外部“符号”)。
    深入理解const char*p,char const*p,char *const p,const char **p,char const**p,char *const*p,char**const p
    volatile学习
  • 原文地址:https://www.cnblogs.com/mingfeng002/p/4063105.html
Copyright © 2020-2023  润新知