为什么 OnActivityResult() 从未被调用?

发布于 2024-11-17 23:16:06 字数 2166 浏览 4 评论 0原文

这就是我启动选项卡活动

  Intent i = new Intent("walk.me.TAB");
        startActivityForResult(i, STATIC_RESULT);

注意的方式:STATIC_RESULT=-1RESULT_OK;

这就是我完成 Tab 活动的方式

((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()文档保证 OAR 将在 OR 之前被调用?我做错了什么?我没有在清单xml中声明

单实例

单任务

主要活动的

This is how I start the Tab Activity

  Intent i = new Intent("walk.me.TAB");
        startActivityForResult(i, STATIC_RESULT);

Note: STATIC_RESULT=-1 or RESULT_OK;.

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();   
}

And here is my OnActivityResult implementation:

@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"));
                  }
                 }}

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

or

singleTask

for the Main activity.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久夏青 2024-11-24 23:16:06

你说STATIC_RESULT是-1?

requestCode 必须是正整数。

startActivityForResult()

参数

intent 启动的意图。

requestCode 如果 >= 0,则当 Activity 退出时,此代码将在 onActivityResult() 中返回。

You say STATIC_RESULT is -1?

The requestCode has to be a positive integer.

startActivityForResult()

Parameters

intent The intent to start.

requestCode If >= 0, this code will be returned in onActivityResult() when the activity exits.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文