我的应用程序有问题。我有一个名为ExperimentView的活动,它有一个名为FrameRoll的内部类,它实现了Runnable。
public class ExperimentView extends Activity implements OnClickListener,{
public void onCreate(Bundle savedInstanceState) {
//Other stuff
//Call the gpshandler activity
gpsCall();
}
public void gpsCall() {
if (gpsEnabled.equalsIgnoreCase("true")) {
Intent gpsHandler = new Intent(ExperimentView.this,
GpsHandler.class);
startActivityForResult(gpsHandler,
GPSHANDLER_ACTIVITY_RETURN);
finish();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//retrieve the data
}
public class FrameRoll implements Runnable {
//do other stuff
}
}
我从onCreate方法调用子活动以检索一些gps数据。成功检索gps数据。
public class GpsHandler extends Activity {
//obtain location
enter code here
Intent resultIntent = new Intent();
resultIntent.putExtra("location",
optimalLocation.toString());
setResult(Activity.RESULT_OK, resultIntent);
}
当我尝试从内部类(frameroll)调用子活动时,子活动正常运行,但实际上从未调用过ExperimentVIew中的onActivityResult方法,所以我没有得到任何数据。
public class ExperimentView extends Activity implements OnClickListener,{
public void onCreate(Bundle savedInstanceState) {
//Other stuff
//Call the gpshandler activity
gpsCall();
}
public void gpsCall() {
if (gpsEnabled.equalsIgnoreCase("true")) {
Intent gpsHandler = new Intent(ExperimentView.this,
GpsHandler.class);
startActivityForResult(gpsHandler,
GPSHANDLER_ACTIVITY_RETURN);
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//retrieve the data
}
public class FrameRoll implements Runnable {
gpsCall();
}
}
我尝试了不同的东西,其中包括在嵌套类中实现onActivityResult
,尝试执行类似ExperimentView.this.startActivityForResults()
的操作,我在gpshandler中打印了callingActivity,它是ExperimentView。
我试过的每个方法都失败了。只有在从onCreate
调用子活动时才会调用onActivityResult。是否有人知道我该怎么办?
Thanx:)
答案 0 :(得分:1)
onActivityResult
。因此,您需要在设置结果后调用finish();
。例如:
setResult(Activity.RESULT_OK, resultIntent);
finish();
*确保GpsHandler
课程符合活动的正确实施,因为它似乎不会覆盖 onCreate 和/或其他方法。