how to open google.navigation intent inside android view or fragment - android

Is it possible to open google navigation intent inside my appln (in a view like a fragment). I would like to display other info to the user as the navigation is going on.

No the intent starts an activity which means you leave your app completely and go to the google navigation app

Related

Using Intent to launch a new fragment

I know it sounds erroneous, "using intent to launch a new fragment?". You may say it should be activity, not fragment if we are talking about Intent. But according to the JetPack Preferences documentation we can use Intent to launch a new fragment.
Set an Intent
You can set an Intent on a Preference to launch a new
Fragment, Activity, or separate application whenever the Preference is
tapped. This is the same as using Context.startActivity() with a given
Intent.
As you can see no example provided about launching fragment with Intent.
If there is a way to achieve this i would like to learn.
Because I am developing a single activity app with fragments, there is navigation component and bottom navigation menu. Trying to use a new activity changes lots of things.
I am just trying to open another fragment when user tap a Preference.

Switch to my app from system overlay view

I have made a system overlay Icon similar to the one here: https://github.com/mollyIV/ChatHeads
I want it to open my app using the click listener of the icon. I am able to make it open MainActivity using context.startActivity(intent) with FLAG_ACTIVITY_NEW_TASK.
But I would like to open my app as if it was opened from the task switcher(Whatever activity is open, in the same state). How do I accomplish this?
You are using FLAG_ACTIVITY_NEW_TASK
If set, this activity will become the start of a new task on this
history stack.
Try to use FLAG_ACTIVITY_SINGLE_TOP:
If set, the activity will not be launched if it is already running at
the top of the history stack.
Source: http://developer.android.com/reference/android/content/Intent.html

What is base intent?

from : http://developer.android.com/guide/topics/manifest/activity-element.html
android:relinquishTaskIdentity
Whether or not the activity relinquishes its task identifiers to an
activity above it in the task stack. A task whose root activity has
this attribute set to "true" replaces the base Intent with that of the
next activity in the task.
What is base intent here?
The base intent is the root intent that initially launched your app.
Most common one is probably the one that any app has when responding to the touch on the app icon. The LAUNCHER intent.
But it can be a custom one, for example, when you respond to custom scheme/url. But here is the trick and how relinquishTaskIdentity can be useful :
Say you start your app with the launcher icon. Your base intent is now the default one.
Now, say your app is completely killed (or you've backed with the hardware icon until your app closes) and you use a custom scheme/url to open your app, at this point the base intent is not the default one. It's the one generated from the scheme/url you clicked on and may contain custom data also. Now if you just close your app with the home button and reopen it, you will just resume where you were at. But if you back, back, back... with the hardware button until your app closes there is the trick : reopening it from the recent apps/multitasking view will reuse the base intent to open it and in this particular case it will still be your custom scheme/url intent and this can be very annoying.
Why annoying? Say the scheme/url your user clicked on was used to auto login and he succeeded: you don't really want to process this url/intent again just because your user backed up until its app closed and reopened it via recent apps/multitasking view, right?
Use relinquishTaskIdentity! This is very dependent to your setup and how your app is configured as for the Activities versus Fragments, but here is an example:
In the particular case I mentioned with the auto login via a link you could have an Activity that is dedicated and is only responding to scheme/url. This same activity should be different than the one flagged as LAUNCHER. and using the property relinquishTaskIdentity="true" on it will make the base intent become any subsequently shown activity via that one.
So what's the benefit in our case? The user can't enter the app with a custom scheme/url generated intent anymore unless he/she really clicked on one supported by your app.

Open Browser as Intent but don't keep it on the Activity stack

I'm having some problems with understanding the activity stack and the behaviour of how it affects my app.
Upon clicking a button it starts an Intent which opens the browser. When I'm in the Browser and I press the home button I land onto the homescreen. Now if I start my app again via launcher it opens the browser instead of my app. How can I circumvent opening the browser upon launching my app?
Right now, the code to open an url looks like this:
private void openUrlExternal(String url) {
Intent openUrlIntent = new Intent(Intent.ACTION_VIEW);
openUrlIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
openUrlIntent.setData(Uri.parse(url));
startActivity(openUrlIntent);
}
Am I using the wrong flags? If so, what flags do I have to use?
Thanks in advance!
Try like this:
openUrlIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
openUrlIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
That should disassociate the browser task from your own which means when you re-launch yours it should go to your Activity instead of the browser.
However it also depends on where you are calling openUrlExternal() from. If you call this when your activity launches it is still going to take you back to the browser, but if you call this from an event listener (i.e. Button click) then it shouldn't get called when you re-launch your app.
I don't think the accepted answer is exactly correct. It depends on what you intend (no pun intended, heh) to do.
Using Intent.FLAG_ACTIVITY_NEW_TASK it means that the launched activity is completely separate from the launching one. In particular, you can switch to the old activity with the Apps button without exiting the new one.
Using Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET means that the user will be returned to the previous activity when it's launched from the apps drawer.
In both cases launching the app again will get you to the previous activity. The main difference will be whether both activities (or just the last one) are shown in the app switcher.

Launch browser from within app - how do you get back to the app?

I've got the following to open up a browser from within an Android app.
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
How do you get the user back to the app after they have viewed the page?
Edit
I have android:noHistory="true" set in my manifest for the Activity calling the Intent.
If the calling Activity is in the Backstack (as default) the user would press "back" to peal the top layer off the stack.
However if the browser closes, the Activity does too, and the last Activity in the Backstack comes to the fore. If you own the site your going to and can put a "back" button in it (With javascript window.close() or similar), the activity will close and your applications topmost activity in the stack will resume.
If your Activity isn't in the backstack then I would suggest instead of sending the user to the browser Task use a custom Activity containing a WebView giving you full control (such as manually starting the original Activity through an Intent)
You can't. They have to press the back button to get back to your app.

Categories

Resources