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
Related
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.
I have a App where I can start a call. When the call is running, I have to go back to my app more specifically to my Activity. My idea was to bring the current Activity in foreground.
Now I have this solution:
Intent it = new Intent();
it.setComponent(new ComponentName(CheckVehicleActivity.this.getPackageName(), CheckVehicleActivity.class.getName()));
it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
CheckVehicleActivity.this.getApplicationContext().startActivity(it);
This is already working.
But: I have a Bluetooth Connection too and when I do it this way, the communication doesn't work anymore. I don't know why this is happening. Then I have to cancel and start my Bluetooth connection again. But this causes other problems in the hole process of the usage of the app.
So my question is:
Is there a way to bring the app in foreground when the call is running, without using an Intent. Or does anyone know an other solution to solve my problem?
You cannot bring another activity into the foreground without intent as this goes against the entire Activity approach that android utilizes.
I currently have two activities in my application.
The second activity in the application prompts a notification icon to be presented in the notification bar.
The intent from the first activity to the second uses the FLAG_ACTIVITY_SINGLETOP and the FLAG_ACTIVITY_CLEAR_TOP flags in the intent. The same goes for the intent used in the PendingIntent from the notification.
My aim is that the second activity is only a single activity and only created once, then when the user leaves via the home button and then goes back to the activity via the notification, the instance that was running comes back and onCreate is NOT called.
This approach works on almost all devices, however testing on one device in particular (A Sony Xperia device - 4.0.4) has shown that it doesn't work in all cases.
On the Sony Xperia the onCreate of the second Activity is always called when it is entered into by the user, even from the notification.
I have tried using singleTop in the Manifest as well without success. Is this a bug in the device or am I doing something wrong? Perhaps missing a flag I need or something along those lines?
If anyone wants more specific code or information please let me know and I will post it.
First of all, please note that it is up to Android to kill your Activity when your app is backgrounded. So there is no guarantee that your activity will stay alive while your app is backgrounded.
In any case, in my projects I end up using singleInstance launch mode for activities that only one instance should be running at the same time.
Just try to update your AndroidManifest with singleInstance launch mode for this activity:
<activity
android:name="com.your.package.YourActivity"
android:launchMode="singleInstance"/>
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.
Give me a little guidance:
as My Application is running with Broadcast Receiver and when ever my application in Background and any incoming event comes it triggers the my Application.
Now we want as We are listening or playing some video file or browsing on Android Phone
and with incoming event occur and my application launch(already running in Background),
If i will ignore the event , we want to go back previous running task (Like browsing, playing
video file application), How we can achieve?
Now I am using The store the running application package and Activity info before triggering the Event , and after finishing using this info we resuming the Activity and
It working fine but Only with Gallery Application Playing of Vedio file is not fine , It Crashes the Application and relaunch the Gallery App.
Please give me some Valuable points to make it up?
On calling finish, Previous application resume(Playing of Media file) but when next time
on getting broadcast intent and try to launch the Activity , The Activity is not launching
and application itself crashing.
After a long back I got solution of my problem and we need only use to this api
moveTaskToBack(true);
and automatically resumes the previous running task(like browser, media application or any thing)
Have you tried to start you activity by
startActivityForResult(Intent intent)
When you call finish() in the Activity you should return the the previous one, I am not sure if this will function over between Activity running in different applications. Give it a try :D