无法获取触发onActivityResult()的Android? [英] Cannot get to trigger onActivityResult() android?
问题描述
我有一个 DataActivity
有要求用户填写一个表格,然后将数据返回到 MainActivity
I have a DataActivity
which has to ask the user to fill out a form and then return the data to MainActivity
DataActivity
从 MainActivity
这样叫:
Intent i = new Intent();
i.setClass(this, DataActivity.class);
startActivityForResult(i,RESULT_OK);
DataActivity
应该返回数据的意图 MainActivity
是这样的:
DataActivity
should return data intent to MainActivity
like this :
Intent i = new Intent();
i.putExtra("funcX", ((EditText)findViewById(R.id.data_eq_x)).getText().toString());
i.putExtra("funcY", ((EditText)findViewById(R.id.data_eq_y)).getText().toString());
i.putExtra("constants", (Serializable)constants);
setResult(RESULT_OK,i);
finish();
但 onActivityResult
从不叫 MainActivity
在此之后...
每当我尝试访问 funcX
或 funcY
在 MainActivity
,我得到NullPointerException异常。
but onActivityResult
is never called in MainActivity
after this...
Whenever i try to access funcX
or funcY
in MainActivity
, I get NullPointerexception.
注:常量
变量可事实上为空时,我在测试这个code
NOTE: constants
variable can be and in fact was null when i was testing this code.
我在模拟器上开发在Android 2.2。
I'm developing on Android 2.2 on the emulator.
推荐答案
请阅读参数<一个文档href="http://developer.android.com/reference/android/app/Activity.html#startActivityForResult%28android.content.Intent,%20int%29"相对=nofollow>关于<请求code href="http://developer.android.com/reference/android/app/Activity.html#startActivityForResult%28android.content.Intent,%20int%29"相对=nofollow> startActivityForResult
Read the documentation for the parameter requestCode on startActivityForResult
要求code。如果> = 0,code将在onActivityResult()返回 活动时退出。
requestCode If >= 0, this code will be returned in onActivityResult() when the activity exits.
RESULT_OK等于-1。
RESULT_OK is equal to -1..
更改您的要求code到一些积极的价值,它的工作
Change your request code to some positive value for it to work
Intent i = new Intent(this, DataActivity.class);
startActivityForResult(i,345);
这篇关于无法获取触发onActivityResult()的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!