为什么在Android中不调用onActivityResult? [英] Why is onActivityResult not called in Android?

查看:329
本文介绍了为什么在Android中不调用onActivityResult?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

启动我的应用程序时,我会显示启动画面.该页面在一个线程上显示10秒钟.

When I my app is launched I am showing a splash screen. That page is been shown for 10 sec, running on a thread.

当结果切换到新活动时,我想点击服务器中的URL,我将获得一个返回值,可用于我的进一步实现.

When it switches over to new activity on a result I want o hit a URL in server and I will be getting a return value which I can use for my further implements.

这是我的代码:

private final int SPLASH_DISPLAY_LENGHT = 1000;

new Handler().postDelayed(new Runnable()
        {
            @Override
            public void run() 
            {
                Log.e("Handler ","run");
                Intent myIntent = new Intent(getApplicationContext(), CaptureActivity.class);
                startActivityForResult(myIntent, imgDL);
                finish();
            }
        }, SPLASH_DISPLAY_LENGHT);



public void onActivityResult(int requestCode, int resultCode, final Intent data) 
      {
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == imgDL) 
          {     
              Log.e("onActivity Result","");
              urlHitMethod("http://XXXXXXXXXXXXXXXXXX.com/banner_scan");
          }
      }

但是这里没有调用onActivityResult.该如何解决?

But here the onActivityResult is not called. How to fix this?

推荐答案

在CaptureActivity.class中,您必须设置结果,然后在第一个活动"中的onActivityResult中检查结果代码

In the CaptureActivity.class you have to set the result and then check in the onActivityResult in the First Activity the result code

在CaptureActivity.class中,它应该类似于以下内容

In the CaptureActivity.class it should be like the following

 Intent in = new Intent();
    setResult(1,in);//Here I am Setting the Requestcode 1, you can put according to your requirement
    finish();

这篇关于为什么在Android中不调用onActivityResult?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆