Activity is not calling back from browser - android

I have an activity that takes an "intent" to the browser, I see the page on which connect and when I return to my work I press the button to go back to my activity. The problem is that it gets stuck in the browser. Is there any solution? Thank you very much for everything and sorry for my English.
here is my code
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(/*my url*/));
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
startActivity(intent);

The Intent you used is just to open browser. If you want to handle the result then you need to consider implementing Custom WebView Activity. So that you can do what ever you like with the browser.

Ahhhh... My bad.!!!!.. I have checked my manifest file ..and I have put NoHistory=true on my parent actvity.

Related

Android - backbutton - restarting app

I designed a app with WebView.
Now I am facing issue, while clicking back-button of WebView of Android app. It is
restarting app instead of Homepage/Menu.
Any idea why this is happening?
I think you use the Intent to webview from Home activity.
if you use Intent, dont use finish() after start the Intent like below.
Intent i=new intent(this,WebviewActivity);
startActivity(i);
HomeActivity.this.finish(); // dont use this line, it destroys homeactivity.
if you doesn't use the Intent, post your code clearly.
Hope this Helps.
Happy Coding :)

can't go back to the previous activity

This is how my app opens a page in default browser
Intent i = Intent.parseUri("http://www.google.com", Intent.URI_INTENT_SCHEME);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Once the browser activity is active, I can't navigate back to my app using back button. It goes the activity before my app. My app/activity is not destroyed though as I can still resume it from the app list. I suspect my activity is 'removed' from the back stack somehow. Please help me debug/fix this. Thanks.
try to use Intent.ACTION_VIEW
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(myUrl));
startActivity(intent);

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

remove activity from stack

I am developing an application in android. I am new in android.
In my application I have a category selection activity from that user have to check a check-box, based on that he will get view on another screen. I have a menu button in 3rd screen in that I have a button for selecting category, when I click on that button its also works fine but when I click back button it will redirect me 2 times at same activity... How to remove this problem? I have used finish() method but its also creates problem its get's me out from the application directly...
I want redirect to selection activity and it should not show me 2 times when I click back button ....
Is there any way please redirect me thank you.
a call to finish() should work so you schould check your code for multiple calling the wrong method or something like this.
Intent intent = new Intent(activity, activityClass.class);
activity.startActivity(intent);
finish();
you should also take a look at the Intent flags:
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Your question isn't clear enough for me to know if this will solve your problem, but if you include the following attributes on your Activity in AndroidManifest.xml, the so-attributed Activity will never appear in your history list.
android:excludeFromRecents="true"
android:noHistory="true"
As for removing something from the history, I'm not sure how to do that, but I'm interested in the answer!
You should call finish before you call Intent and go to next activity. so the current task is finished and will not be saved in stack and then you intent activity will come on top of stack. If you directly want to go to Selection activity, override onBackPressed() and intent to the activity you want to go to.
There are different flags that you can use to control how your activity interacts with the activity history stack. Two that might be of interest to you are FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_NO_HISTORY.

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