kill an ActionView (Web browser) in the Android stack of my application - android

I need to call a ActionView in my application. But after used it, I would like to kill it of my stack (if I press return,I don't want to come back in this view). How can I do?
Here how I call the actionView:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken.getAuthorizationUrl()));
startActivity(i);
Thanks!

Related

Application button to open current/new instance of another app

I have two applications, A and B. In app A I've added a button which opens app B.
When the button is clicked I want to open App B if it's not already running, otherwise I want to bring the app to the front.
This is the code I use:
Intent intent = getPackageManager()
.getLaunchIntentForPackage(
"com.myapp.something");
if (intent != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
The code seems to work, but the problem is that if I open app B from app A (using this code) and then click directly the icon of App B, I get two instances of the app, which is undesired.
How can I open the app, as the code does, but also get the same instance even if the app's icon is clicked?
Add Intent.FLAG_ACTIVITY_CLEAR_TOP

How to close programatically the webbrowser?

After showing the webbroser with this code :
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
How to close it programatically ?
How to close it programatically ?
You can't.
It's not under your control. A new activity has been launched and you must wait for the user to stop interacting with it (for example, when they click the back button) for control to return to your activity.
If you want fine-grained control you should probably look at embedding a WebView in your own activity or fragment, then you have full control over opening and closing it.
If you mean the Browser App, you may close it by code finding his PID and killing it but is discouraged.
Read this post

Managing the back stack after oauth login on Android

I am implementing oauth login in Android, and I'm stuck on one point. I am required to redirect to the native browser to initiate the login (rather than use an embedded WebView of my own), but that is causing issues with the back stack. My goal is simple: return to my activity after the redirect with no trace of the native browser in the back stack. Here is the closest I've come so far:
To initiate the login from my activity I use:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
context.startActivity(intent);
I have a separate activity to receive the return redirect and handle the rest of the login process. I don't really care whether it's a separate activity or not, it is just my current solution. In its manifest I set android:noHistory="true". Once it finishes the login process, I attempt to return to the first activity using code like this:
Intent intent = new Intent(context, OrigActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
However, this ends up creating a second copy of the original activity, and when I press back it returns me to the first copy. In other words, it does not seem to respect FLAG_ACTIVITY_CLEAR_TOP. Did I miss something simple to make it work, despite all my searching? Or is there some other way I should go about all of this?
Edit: It turns out the problem stems from the fact that the browser is launched in a separate task. From some Android documentation:
... if your application issues an intent to open the Android Browser, its activity is not placed in the same task as your application. Instead, either a new task starts for the Browser or, if the Browser already has a task running in the background, that task is brought forward to handle the new intent.
If I set my original activity's launch mode to singleTask it properly brings it to the foreground instead of creating a new copy, but a new problem occurs. The browser is now in the back stack behind all of my activities, so now it seems FLAG_ACTIVITY_NO_HISTORY is not being respected. I'm not sure if that brings me any closer to a proper solution ...
Edit 2: Correction: if the browser was not running before I launched it, everything works perfectly. However, if it WAS already running FLAG_ACTIVITY_NO_HISTORY seems to have no effect on it.
What you're seeing makes sense because calling the browser with the FLAG_ACTIVITY_NO_HISTORY wouldn't remove back stack from PRIOR to the start of your application.

Android Browser Intent back button

Hello I am lauching the browser from my application using an intent such as:
String url = "XXXX";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
but when I press back on the browser i want to go back to the my application, instead of going to the options of the browser. how can i control this behaviour?
You can't as the back button implementation is now under control of Browser Application.
Implement a WebView in your application and handle Back Key Pressed is the only option.
Try:
Intent i = new Intent(Intent.ACTION_VIEW);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setData(Uri.parse(url));
startActivity(i);
A task (from the activity that started it to the next task activity) defines an atomic group of activities that the user can move to. Tasks can be moved to the foreground and background; all of the activities inside of a particular task always remain in the same order. You can find more about it here: http://developer.android.com/guide/components/tasks-and-back-stack.html

Opening browser activity, but prevent it from being in the activity history

I'm working on an app that launches the browser activity to perform a Twitter OAuth authorization. This process uses a callback url which will re-launch the activity that started the browser activity in the first place.
My problem is that the browser pages remain in the history stack and when the user then clicks back from the preferences activity that launched the browser in the first place, they don't go back to the app's main activity, but instead are brought back to the browser. I've tried adding flags to the launching intent to prevent history and reset on clear, but it doesn't seem to work when running on my phone, only on the emulators.
Here is the code I'm using to launch the browser activity:
Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));
webIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
webIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
webIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
ctx.startActivity(webIntent);
Anyone have any idea what might be wrong?
Set the activity flag to Intent.FLAG_ACTIVITY_CLEAR_TOP after starting it. This way, the task will be deleted form the app stack so your main activity remains the top one on every new launch:
ctx.startActivity(webIntent);
browserIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
call
finish();
after
ctx.startActivity(webIntent);
Hi i have the same problem at the moment. I think the solution is to start the activity you want to return to with a special flag:
Intent intent = new Intent(this, acticityToReturnTo.getClass());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
The problem is that is does not work (on 1.6 at least).. But maybe someone finds a solution for this. I think FLAG_ACTIVITY_CLEAR_TOP is exactly what we.
I found that Intent.FLAG_ACTIVITY_NO_HISTORY works only if the browser was not running before. If I restart Android and run my app which call browser everything work well. But when I start browser before my app, browser will stay in history.
Here is related question also, but with no really working solution
How can I do that in Android. Activity -> WebBrowser -> Acrivity, but Press Back not see the WebBrowser

Categories

Resources