我遇到了无法从活动中回调的问题。将表单 Activity 1 输入到 Activity 2 但它无法返回。谁能告诉我我哪里做错了?
这是我的代码:
活动一:
OnClickListener changeTextOnClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Setting.class);
startActivityForResult(intent, CHANGETEXT);
}
和
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case CHANGETEXT:
Bundle b = data.getExtras();
this.Text = b.getString("Text");
}
}
}
活动二:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bundle b = new Bundle();
Intent intent = new Intent();
newText.setText(newText.getText().toString());
Toast.makeText(getApplicationContext(),
newText.getText().toString(), Toast.LENGTH_LONG).show();
b.putString("Text", newText.getText().toString());
intent.putExtras(b);
setResult(RESULT_OK, intent);
finish();
}
显现:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.shotboxv3.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.shotboxv3.Setting"
android:label="@string/app_name" >
</activity>
</application>