views:

818

answers:

3

Hi all,

I currently have an application that naturally gets pushed to the background when the home key is pressed.

The activity losses focus but continues running in the background.

So I want to know is it possible to bring the application back to the foreground when the user presses the green key (call button) on the device?

+1  A: 

There is no way to completely override the call button behaviour without user interaction. When pressing it, the user will be asked to choose between the default action (launching the dialer), or launching your application.

If you wanted to do this, your manifest would look something like this:

<activity android:name=".SomeActivity">
    <intent-filter>
        <action android:name="android.intent.action.CALL_BUTTON" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
Christopher
Thanks for that Christopher That gives the option to start my activity However this is what I want to happen: The user clicks green key to bring up the native dialler, they dial a call, my app detects it and pops up a dialog saying it has detected and outgoing call I then want the user to be able to press home or navigate away from the dialog so its in the back ground and then when they press the green key the dialog gets focus again on the foreground.So I only want to trap the green key when my activity is already running and I want to ignore it if my activity is not running is this possible?
Donal Rafferty
No. By pressing the call button, the framework is calling `startActivity()` and so looks for an activity to start. In this case yours would potentially start due to the above XML intent-filter. You can't conditionally decide to handle the intent from a `startActivity()` call.
Christopher
So there is no way I can change when my Activity wants to be an option from the green key and when it doesn't?
Donal Rafferty
+1  A: 

Also note that many devices (Nexus One and Droid for example) don't have the call button at all.

mbaird
A: 

Hi is there any way i could check that my application is running on foreground or resting in the background.

junaid
Hi there. You should search the site and if not already answered, ask this as a separate question. Currently you have posted it as an answer to an existing question.
Christopher