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:
/** 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中调用。这本书几乎就是这样。这是什么问题?
我试过的东西: - 使用Activity.RESULT_OK作为结果代码(转换为-1); - 从处理程序中删除setResult()和finish()调用,并调用外部方法来调用它们。
我没有看到任何错误。这是清单,没有错误:
<?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>
是什么给了什么?
答案 0 :(得分:1)
在您开始的活动(KitActivity.class)中成功执行此操作
Intent intent = this.getIntent();
intent.putExtra("SOMETHING", "EXTRAS");
this.setResult(RESULT_OK, intent);
finish();
否则你输入RESULT_CANCELED而不是RESULT_OK
答案 1 :(得分:0)
取代:
protected void onActivityResult(int reqCode, int resCode)
使用:
protected void onActivityResult(int reqCode, int resCode, Intent intent)
当您查看文档时会发生什么...... -_-