为什么从不调用OnActivityResult()? [英] Why is OnActivityResult() never called?
问题描述
这就是我启动标签活动"的方式
This is how I start the Tab Activity
Intent i = new Intent("walk.me.TAB");
startActivityForResult(i, STATIC_RESULT);
注意:STATIC_RESULT=-1
或RESULT_OK;
.
这就是我完成Tab活动的方式
This is how I finish the Tab activity
((Button)viewItem.findViewById(R.id.gotherefav)).setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
if(ime!=null)
{
b.putString("ime",ime.toString());
b.putIntArray("koordinati&kategorija", coordAndCat );
b.putBoolean("klik", true);
FinishWithResult(b);
}
return false;
}});
public void FinishWithResult(Bundle b)
{
Intent i = getIntent();
i.putExtras(b);
setResult(Activity.RESULT_OK, i);
Log.i("in FINISH", "settig Activity Result");
finish();
}
这是我的OnActivityResult
实现:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("in OnActivityResult", "Activity Result");
Toast.makeText(getBaseContext(), "DOJDE", Toast.LENGTH_LONG).show();
super.onActivityResult(requestCode, resultCode, data);
Log.i("in OnActivityResult", "Activity Result");
if (requestCode == STATIC_RESULT) {
if (resultCode == RESULT_OK) {
Toast.makeText(getBaseContext(), "DOJDE BUNDLE", Toast.LENGTH_LONG).show();
Bundle preferenciOdTab = data.getExtras();
if(preferenciOdTab !=null && preferenciOdTab.getBoolean("klik", true))
{
mapView = (MapView)findViewById(R.id.map);
isFavorite=preferenciOdTab.getBoolean("klik");
drawFavorite(preferenciOdTab.getString("ime"),preferenciOdTab.getIntArray("koordinati&kategorija"));
}
}}
为什么从不调用onActivityResult
并直接转到OnResume()
,而不管文档保证在OR之前将调用OAR?我做错了什么?我没有在清单xml中声明
Why is onActivityResult
never called and directly goes to OnResume()
regardless of the documentation garantees that OAR will be called before OR? What I'm doing wrong? I dont have stated in manifest xml
singleInstance
singleInstance
或
singleTask
singleTask
主要活动.
推荐答案
您说STATIC_RESULT是-1吗?
You say STATIC_RESULT is -1?
requestCode必须为正整数.
The requestCode has to be a positive integer.
参数
意图开始的意图.
intent The intent to start.
requestCode如果> = 0,则活动退出时,此代码将在onActivityResult()中返回.
requestCode If >= 0, this code will be returned in onActivityResult() when the activity exits.
这篇关于为什么从不调用OnActivityResult()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!