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.
Related
I'm trying to develop a VoIP call application on Android and there is a problem which I cannot find any solution. Also, I don't know how to search the problem, so let me explain the scenario:
User sends the app to background by pressing the home button (minimize the app). Then when he/she gets a call, my call screen activity comes up. It is ok till here. My problem is the last activity comes to foreground when the call ends, but as the user sent the app to background before the call received he/she wants the app to stay in background after the call ended.
How can I make the application stay in the background after the call ends?
Before calling finish() when your application's Activity ends, start the HOME screen:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
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
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.
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'm developing an Android application that have a button to init a call phone when is clicked.
I want to detect when the call phone is answered and automatically put the native phone application in background and show my application again. Meanwhile, the call phone runs in background.
The result has to look like when you click the back button of the smartphone or if you open manually my application while the call phone is in progress. But this should be done automatically without pressing any buttons.
I know that I have call listeners to do something when the state of call is ringing, offhook or idle, but the problem is putting the call application in background from my application.
Sequence:
user clicks button in my app to launch native phone application (Android).
the phone call starts (call state: ringing).
the phone call is off hook (call state: Off-hook).
automatically, my application detects it and puts the native phone app in background and puts my application in foreground.
Is it possible and how I can do it?
Create a background service and implement BroadcastReceivers to listen the call state triggers.
you can put your app in the foreground after the call was answered using Activity start.
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
now the problem is that the started activity will be a NEW activity (It will clear all previous activites - without these flags it won't return back from the call screen).
i don't know how can I actually return to already working activity in the background.