清除回堆栈活动是从Web浏览器打开的网址&QUOT后,应用程序的名字://com.appname/" [英] Clear back stack after activity is opened from web-browser by url "appname://com.appname/"

查看:121
本文介绍了清除回堆栈活动是从Web浏览器打开的网址&QUOT后,应用程序的名字://com.appname/"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个活动,即启动浏览器支持OAuth认证过程,最后浏览器接收重定向到URL应用程序的名字://com.appname,即回调到我的活动。 (活动声明,它可以查看此类URL)

My application has an activity, that launches oauth-authorization process in browser, and finally browser receives redirect to url "appname://com.appname", that calls back to my activity. (activity declared that it can view such urls)

一切正常,但如果用户presses后退,他又回到了Web浏览器。 我要清除历史堆栈,当活动叫回来,让这个活动的根和顶级完成这项任务。

Everything is OK, but if user presses "Back" he goes back to web browser. I want to clear history stack when activity is called back, to make this activity root and top in this task.

我可以利用这种情况有什么标志或钩?

What flags or hooks can I use for this case?

<打击> 我只找到一个丑陋的解决方案: 接受应用程序的名字://com.appname网址特殊的加格活动,将开展的主要活动在其onResume

I found only one ugly solution: receive appname://com.appname urls to special "Gag" activity, that will launch main activity on its onResume.

我试图让主要活动singleTask,推出浏览器的新任务,设置标志NO_HISTORY和EXLUDE_FROM_RECENTS,CLEAR_TOP,设置clearTaskOnLaunch =真。 试过了标志和标签的多种组合中体现 - 没有什么帮助。

I tried to make main activity "singleTask", launch browser in new task, set flags NO_HISTORY and EXLUDE_FROM_RECENTS, CLEAR_TOP, set clearTaskOnLaunch="true". Tried many combinations of that flags and tags in manifest - nothing helps.

我解决了这个问题:
1)在AndroidManifest.xml中 - 设为clearTaskOnLaunch =真 2)启动浏览器的新任务(FLAG_ACTIVITY_NEW_TASK),并完成当前活动(以完成当前任务)。
3)覆盖onBack pressed:不是完成这项活动号召moveTaskToBack(真正的);

I solved this problem:
1) set clearTaskOnLaunch="true" in AndroidManifest.xml
2) Launch browser in new task (with FLAG_ACTIVITY_NEW_TASK), and finish current activity(to finish current task).
3) override onBackPressed: instead of finish this activity call to moveTaskToBack(true);

当用户presses回 - 任务(浏览器是在它的根目录)被切换到后台和用户看到自己的主屏幕。

when user presses back - task(browser is in root of it) goes to background and user see his homescreen.

当用户再次启动应用程序 - 它从现有的实例打开,清除任务,并成为它的根目录(因为clearTaskOnLaunch =真)

when user launches application again - it opens from existing instance,clears task and becomes root of it (because clearTaskOnLaunch="true")

推荐答案

当点击链接应用程序的名字://com.appname在Web浏览器,浏览器调用你的活动,但浏览器没有叫光洁度本身,你不能改变浏览器。

When click link appname://com.appname in web browser, the browser call your activity, but browser did not call finish itself, you can't change the browser.

我觉得做,有一个web视图里面可以解决这个新的活动。

I think that make a new activity that has a webview inside can solve this.

您将启动Android浏览器中的新的活动代替。 在新的活动,设置webViewClient导航回您的主要活动:

You will start that new activity instead of android browser. In the new activity, set webViewClient to navigate back to your main activity:

wv_mem_rank.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if(url.startWith("appname://com.appname"))
        {
            startActivity();
            finish();
        }
        view.loadUrl(url);
        return true;
    }
    public void onLoadResource (WebView view, String url) {
    }
    public void onPageFinished(WebView view, String url) {
    }
});

这篇关于清除回堆栈活动是从Web浏览器打开的网址&QUOT后,应用程序的名字://com.appname/&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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