的onActivityResult不会被调用 [英] onActivityResult not being called

查看:242
本文介绍了的onActivityResult不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

KitActivity:

KitActivity:

/** in KitActivity, handler invoked after successful transmission **/
private final Handler txHandle = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        boolean success = msg.getData().getBoolean("success");
        dismissDialog(DIALOG_TX_PROGRESS);
        if(success) {
            SharedPreferences.Editor editor = mPrefs.edit();
            editor.putInt("previous_scale", mScaleSpn.getSelectedItemPosition());
            editor.commit();
            //clearFields();
            //showDialog(DIALOG_ETX);
            KitActivity.this.setResult(0);
            KitActivity.this.finish();
        } else {
            removeDialog(DIALOG_FAIL);
            showDialog(DIALOG_FAIL);
        }

    }
};

MainActivity:

MainActivity:

/** in the MainActivity **/
public void startCreateKit() {
    Intent i = new Intent(MainActivity.this, KitActivity.class);
    startActivityForResult(i,0);
}

protected void onActivityResult(int reqCode, int resCode) {
    if(reqCode==0) {
        if(resCode==0) {
            //we good, perform sync
            showDialog(DIALOG_TX_PROGRESS);
            Toast.makeText(this, "Performing Auto Sync", Toast.LENGTH_LONG).show();
            updateKits();
        } else {
            //uh oh
        }
    }
}

createKitBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //Toast.makeText(context, "NEW KIT", Toast.LENGTH_SHORT).show();
            startCreateKit();
        }
    });

的onActivityResult从不在MainActivity调用。这是pretty所书多。有什么问题?

onActivityResult is never called in MainActivity. this is pretty much by the book. what's the issue?

东西,我已经试过:
- 使用Activity.RESULT_OK的结果code(这相当于-1);
- 移除的setResult(),并完成()从处理程序调用和调用外部方法来调用它们。

stuff i've tried: - using Activity.RESULT_OK for the result code (which translates to -1); - removing the setResult() and finish() calls from the handler and calling an outside method to invoke them.

我看不出有什么不对。这里的清单,没有什么歪在这里:

i don't see anything wrong. here's the manifest, nothing awry here:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.conceptualsystems.kitmobile"
      android:versionCode="8"
      android:versionName="@string/version">
    <application android:label="@string/app_name" android:icon="@drawable/icon" android:debuggable="true">
        <activity android:name="MainActivity"
                  android:label="@string/app_name"
                  android:screenOrientation="portrait"
                  android:configChanges="keyboardHidden|orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="ShipActivity"
                  android:label="Ship Kits"
                  android:screenOrientation="portrait"
                  android:configChanges="keyboardHidden|orientation">
        </activity>
        <activity android:name="KitActivity"
                  android:label="Kit Entry"
                  android:screenOrientation="portrait"
                  android:configChanges="keyboardHidden|orientation">
        </activity>
        <activity android:name="ColorActivity"
                  android:label="Color Selection"
                  android:screenOrientation="portrait"
                  android:configChanges="keyboardHidden|orientation">
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest> 

怎么办?

推荐答案

替换为:

protected void onActivityResult(int reqCode, int resCode)

protected void onActivityResult(int reqCode, int resCode, Intent intent)

惊人的什么,当你查看文档发生...... -_-

amazing what happens when you review the documentation... -_-

这篇关于的onActivityResult不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆