How to determine if an application is already active

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to determine if an application is already active

Postby mingboq » Fri Nov 14, 2008 6:21 pm

I have an application that needs to be triggered if certain SMS arrives. The application needs to respond differently when are active or inactive. For example, if the application is not running, it will start running just like when you manually start the application. While you are using the application, then I don't want the current view to be affected. I this case, maybe just popup a notification. Can someone help me with this? Thanks.
mingboq
Freshman
Freshman
 
Posts: 3
Joined: Fri Nov 14, 2008 4:40 pm

Top

Re: How to determine if an application is already active

Postby MrSnowflake » Fri Nov 14, 2008 6:29 pm

mingboq wrote:I have an application that needs to be triggered if certain SMS arrives.
....

I this case, maybe just popup a notification. Can someone help me with this? Thanks.
BroadcastReceiver should _NEVER_ create a window. They should display notifications.

And I don't know how to check if the Acitivity is already running. Normally you can only have 1 instance of an Activity open, so when your BroadcastReceiver shows a notification and the user activates that notification, he knows he is going to see another screen. So then it's not a problem.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby mingboq » Fri Nov 14, 2008 6:40 pm

MrSnowflake,

Thanks for the quick response. I don't understand why a broadcastreceiever should not start a new window. I thought that's exactly what a receiver is supposed to: to start certain activities when something happens. When such a receiver starts an activity, a new window is created, right?
mingboq
Freshman
Freshman
 
Posts: 3
Joined: Fri Nov 14, 2008 4:40 pm

Postby MrSnowflake » Fri Nov 14, 2008 6:52 pm

A BroadcastReceiver should display a Notification so the __USER__ can open up the activity (when _HE_ clicks/touches the notification). The user needs to be in control of Android, not the application developer! This realy is important!

In particular, you may not show a dialog or bind to a service from within an BroadcastReceiver. For the former, you should instead use the NotificationManager API. For the latter, you can use Context.startService() to send a command to the service.
(source: BroadcastReceiver docs)
and
Even if your application is fast and responsive, it can still annoy users. A common example is a background process (such as an Android Service or BroadcastReceiver) that pops up a UI in response to some event.
(source: Design philosophy (seamless))
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Is an Activity already running?

Postby NilsT » Mon Jan 18, 2010 11:15 am

I am confused. I have an Activity that wakes up on an incoming SMS.
It works fine, except that if the activity is already running, it seems like a second instance is created.
My Receiver kicks off the Activity with the FLAG_ACTIVITY_NEW_TASK flag.
According to the documentation it should only create a new 'task', if it doesn't already exist.
And now I just read in this thread I should never try to open a window in a case like this.
Please, give me advice!
(And, please, help me understand the difference between a task and an activity?)
NilsT
Freshman
Freshman
 
Posts: 4
Joined: Tue Aug 25, 2009 9:52 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests