English 中文(简体)
强烈要求 职业介绍
原标题:Wrong requestCode in onActivityResult

我会开始从我的分裂开始新的活动。

startActivityForResult(intent, 1);

并且希望处理导致父母分裂活动的结果:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "onActivityResult, requestCode: " + requestCode + ", resultCode: " + resultCode);
    if (requestCode == 1) {
        // bla bla bla
    }
}

问题在于,我从来不使用<代码>requestCode。 页: 1

0x40001,0x20001。 等等,有一套随机较高的借方。 docs没有说什么。 任何想法?

最佳回答

页: 1 当你这样做时,<条码>requestCode通过<条码>加以改动,该代码有<条码>。

如果您希望获得正确的<代码>resultCode。 在你的活动中:

变化:

startActivityForResult(intent, 1);

:

getActivity().startActivityForResult(intent, 1);
问题回答

要求书并非错误。 在使用v4支持图书馆的碎块时,碎块指数在请求书的16个顶点上编码,你的请求书码在16个底层。 碎片指数后来用于寻找正确的碎片以达到结果。

因此,活动开始成为碎片物体,处理主动反应要求 守则如下:

originalRequestCode = changedRequestCode - (indexOfFragment << 16)
      6             =      196614        -       (3 << 16)

<<>Easier>:

Java: int unmaskedRequestCode = requestCode & 0x0000ffff

Kotlin: val unmaskedRequestCode = requestCode and 0x0000ffff

对16个下限进行核对,仅使其做符合逻辑的工作,16个上限为零

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    final int unmaskedRequestCode = requestCode & 0x0000ffff

    if(unmaskedRequestCode == ORIGINAL_REQUEST_CODE){
      //Do stuff

    }
}

如果你不断公布,然后在<条码>上使用

例如:

public static final int REQUEST_CODE =1;
getActivity().startActivityForresult(intent, REQUEST_CODE);

You can also define
super.onActivityResult(requestCode, resultCode, data)
in Activity (if you overrideonActivityResult) at this

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {

        ...

        default:
            super.onActivityResult(requestCode, resultCode, data);
    }
}

电话:startActative forResult(intent, requestCode) within Fragment

缩略语

  getActivity().startActivityForResult(builder.build(getActivity()), PLACE_PICKER_REQUEST);

主要活动:

if (requestCode == PLACE_PICKER_REQUEST) {
            if (resultCode == RESULT_OK) {    
     //what ever you want to do
            }




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签