处理回单击启动Android的默认Web浏览器后, [英] Handling back click after launching the Android default web browser

查看:161
本文介绍了处理回单击启动Android的默认Web浏览器后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的Andr​​oid应用我想启动默认的Web浏览器用户发送一个验证的网页,然后一经查实使用回调送他们回到我的应用程序。

From my Android app I wish to launch the default web browser to send the user to a verification web page, and then once verified use a callback to send them back to my app.

我有一个功能工作确定,但我有与被拦截在用户决定他们不想验证自己的网页浏览器,点击后退按钮返回到我的应用程序的情况困难的。

I have that functionality working ok, but what I'm having difficulty with is intercepting the situation where the user decides they don't want to verify themselves in the web browser and clicks the back button to return to my app.

我试过用发射startActivityForResult(网页浏览器),这样我就可以使用的onActivityResult()拦截回来的点击,但由于某些原因的onActivityResult()推出的网络浏览器后立即调用,而不是在所有当用户点击回来了。

I've tried launching the web browser with startActivityForResult() so I can intercept back clicks using onActivityResult(), but for some reason onActivityResult() is called immediately after launching the web browser, and not at all when the user clicks back.

下面是一些基本的测试code演示该问题:

Here's some basic test code that demonstrates the problem:

public class MainActivity extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        Log.i("MainActivity","onCreate called");

        Uri uri = Uri.parse("http://www.google.com");

        Intent intent = new Intent(Intent.ACTION_VIEW,uri);

        startActivityForResult(intent,101);

        Log.i("MainActivity","startActivityForResult called");
    }

    @Override
    public void onResume()
    {
        super.onResume();

        Log.i("MainActivity","onResume called");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        Log.i("MainActivity","onActivityResult called");
    }
}

运行此code后输出:

Output after running this code:

I/MainActivity(545): onCreate called
I/MainActivity(545): startActivityForResult called
I/MainActivity(545): onResume called
I/MainActivity(545): onActivityResult called
I/MainActivity(545): onResume called

这时如果用户点击从WEB浏览器,它只是调用onResume()第三次。

Then if the user clicks back from the web browser, it just calls onResume() a third time.

所以考虑到,会有人对我怎么能识别任何建议,当用户点击来自浏览器的后退?

So given that, would anyone have any suggestion on how I can recognise when the user clicked back from the browser?

推荐答案

如何给这是一个尝试:

@Override
public void onWindowFocusChanged(boolean hasFocus)
{
    super.onWindowFocusChanged(hasFocus);
}

这篇关于处理回单击启动Android的默认Web浏览器后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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