Go back after call Intent.ACTION_VIEW in android

寵の児 提交于 2019-12-03 16:10:43

Please refer to Tasks and Back stack in android. You can use two tasks in your application - in first one you do your business, in second - authorization. You start authorization with intent flag FLAG_ACTIVITY_NEW_TASK and use parameter android:clearTaskOnLaunch. Good luck!

I added the following flags to the ACTION_VIEW intent and it solved the going back to browser problem

consumer = new CommonsHttpOAuthConsumer(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
provider = new DefaultOAuthProvider("http://twitter.com/oauth/request_token",
                    "http://twitter.com/oauth/access_token",
                    "http://twitter.com/oauth/authorize");
String authUrl = provider.retrieveRequestToken(consumer, Constants.OAUTH_CALLBACK_URL);
Intent oauthIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));        
oauthIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
oauthIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
oauthIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);

In C you can override back button to go directly to B

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        startActivity(C.this,B.class);
        moveTaskToBack(true);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!