Starting location setting page - android

In my app I need to bring up the location settings page if location is not enabled.
This is done by
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
It works OK, however, once the setting page is finished with, I find I have to tap the back button several times to get back to my app, and on an HTC phone, the setting page sometimes crashes (my app is OK).
Other apps that do this do not seem to have these problems, are there any suggestions as to what they do that I don't?
The code aove is called directly from a View touch event.

In your activity, before starting location source settings, register a broadcast receiver for android.location.PROVIDERS_CHANGED and when you received the broadcast start your activity and unregister your receiver. You might also want to make your activity single-instance.

Related

Activity does not start when called from service when relaunching the app

I have a MainActivity which launches a background service. This service monitors the location of the device and if the device is in particular location, It launches another activity LocationBasedActivity which comes to the foreground plays a video, once complete it launches the MainActivity using startActivity.
This works well for the first time when the app is installed. But when the device is restarted and the app is launched, all logic of detecting the location works, but the LocationBasedActivity is not launched. The call to startActivity is being made, but it returns without any error or exception, the following is the code snippet for launching the LocationBasedActivity from the service
Intent intent = new Intent(MyBackgroundService.this, LocationBasesActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
I tried debugging this, got to the point where the call to Android's tried debugging the startActivity which in turn is calling
This is on Android 4.4 on Tab E. Would really appreciate any help on this issue.
Thanks

User-placed phone call from app sends app to background

My app is meant to be used while on the phone and it has pre-programmed buttons for placing calls to key people.
The problem is when a call is initiated, the phone goes to foreground rendering app unavailable. How to continue phone call but have app come back to foreground automatically ?
So far I have a phone state listener which is working fine, and I use it to fire an intent to my main activity when phone ringing is detected like this,
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
Its not clear what is happening with this. It seems like MainActivity is getting restarted ( or resumed ?), several times actually, but foreground stays unchanged in the phone activity.

Android: reset if reopened after launching external Intent

My app requires location services to be enabled.
I wrote a loader Activity that verifies the different providers, and launches the system settings interface if something needs reconfiguring, much like Google Maps does.
Intent goToSettings = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(goToSettings);
Problem is, if the user navigates away without finishing the settings panel, it's left at the top of the Activity stack and shows up again when the app is brought to foreground (on relaunch, maybe in other scenarios).
How can I "detach" the system settings from my app? I tried combining flags and launch modes, but I can't get it working.
Use intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); to launch the external intent as a separate task.

android hidden app strategy

I'm trying to create an app "hidden" from applications list.
The way i though the user will start the app is through a Receiver listening for NEW_OUTGOING_CALL and intercept a particular number dialed.
The problem is that on new Android versions, this receiver will never be activated if the app never start once. (Starting the application from a BroadCastReceiver (NEW_OUTGOING_CALL doesn't always work)).
I can't figure out a workaround for this problem: the app launcher is totally hidden so the user cannot never launch the app, and the receiver would never be activated if the app will never start.
Is there any other strategy or workaround for hide and launch the app with some kind of secret action?
Create a activity with manifest file pointing it as the the Launcher activity and make it transparent and call its finish method in onCreate. User clicking on that icon will have no idea that the activity is opened. But why don't you show the About application kind of screen in the launcher activity?

multiple instances of gps activity is running at same time

I have got an app tracking GPS.
I am using myLocationOverlay to get location and I have got kind of navigation.
there are two options when closing app.
gps keeps tracking (not calling myLocationOverlay.disableMyLocation;)
gps is disabled.
when GPS keeps tracking it gives Notifications and when I click to the Notification, there is no problem, it opens the currently running activity with pending Intent.
But when I open the same activity again from the application, there appears a new instance of the same activity and it starts to use the GPS and updates the notification.
So two instances of same activity are working at the same time.
I tried to close the previous activity when second instance is opened but I couldn't do it.
I've also used intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); when opening new intent and also put this android:launchMode="singleInstance"
in AndroidManifest.xml but the first created one still works.
I hope someone has an idea.
Try using FLAG_ACTIVITY_CLEAR_TOP in conjunction with FLAG_ACTIVITY_NEW_TASK. When used together, these flags are a way of locating an existing activity in another task and putting it in a position where it can respond to the intent.

Categories

Resources