Bringing an Activity to front

by Teo [GD API Guru] » Sun, 29 Aug 2010 21:14:59 GMT


Sponsored Links
 Hi,

i have multiple instances of the same activity, is there a way to
programatically bring one of the instances to the front? I've read
some existing threads and it seems there's no way to do this... My
specific use case is of a Snooze/Dismiss type of screen. The problem
would appear when the user sets 2 alarms close by:
- first alarm is triggered, so first instance of the activity is
created
- user doesn't dismiss the alarm
- second alarm is triggered, so the second activity instance is
created and comes to the front
- user doesn't dismiss this either
- first activity instance reminds the user about the first alarm
(sound can be played, but the UI is still somewhere in the background)

Any suggestions?

Thanks,
Teo

--



Bringing an Activity to front

by Mark Murphy » Sun, 29 Aug 2010 21:24:21 GMT


 I'm not sure how you would be able to identify which instance to bring
to the front, if they are all the same activity.

Have you considered updating your flow, such that the second alarm
brings the existing activity instance to the front, which then
displays snooze/dismiss options for both alarms?




-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!

--


Sponsored Links


Bringing an Activity to front

by Teo » Sun, 29 Aug 2010 22:00:38 GMT


 That's not a bad idea actually, but that would mean i'd have to keep tabs on
all the stuff myself...

What i'm doing now is using a Handler for the snooze time (don't want to mix
AlarmManager alarms with the app's own alarms). Each Activity instance has
its own Handler, so when the Runnable is run i'm in the context of that
activity instance. This Activity (and its potentially multiple instances) is
started by the AlarmReceiver with startActivity(). Everything is actually
pretty cool, if it wasn't for this focus issue. The activities take care of
themselves and destroy their own stuff when it's time. Making them act as a
single activity, by populating UI fields according to what happens, i would
have to keep record of all the handlers and runnables, and compared to what
i have now i'm not sure it's worth the extra effort.






>



Bringing an Activity to front

by Mark Murphy » Sun, 29 Aug 2010 22:08:52 GMT


 


That will only work if the activity stays in RAM. That's fairly likely
in your case, but not assured.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!

--



Bringing an Activity to front

by Dianne Hackborn » Mon, 30 Aug 2010 03:03:33 GMT


 




You really don't want to avoid keeping track of what you are doing.
 Throwing stuff up into the system and hoping it all comes down in the right
pieces is probably not going to work so well.

Just keep persistent state about what your own app is actually doing, and
drive your interaction with the system through that.



What you are doing is actually going to break on you, as soon as your
process gets killed while it is in the background.

You need to keep this stuff in persistent state, and explicitly manage it.

-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--



Bringing an Activity to front

by Teo » Mon, 30 Aug 2010 03:53:01 GMT


 Will the process/activity be killed if it has a Handler running in it?
Managing the stuff myself would mean i'll have a list of Handlers/Runnables
instead of single fields, but nothing of consequence in the activity changes
(e.g. another app might take focus, not only an activity from my own app,
and i'd still need to bring my activity to the front)






>



Bringing an Activity to front

by Dianne Hackborn » Mon, 30 Aug 2010 14:02:22 GMT


 




There being a Handler with pending (or running) messages has no influence on
when a process will be killed.  The only things that matter for this are the
state of any activities, receivers, services, or content providers in the
process, as described for the process lifecycle.


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--



Bringing an Activity to front

by Teo » Mon, 30 Aug 2010 15:55:33 GMT


 Thanks for the answers.. I guess it would be better to use alarms then and
recreate the activity as needed.







>



Other Threads

1. Handling Sensor Events and optimal way of using SensorGestureDetector?

Hi All

My dbt is that lets say I have the applications like Gallery and
Calendar which want to use Sensor input as another input apart from
touch i/p and key i/p and for this there is a utility say
SensorGestureDetector(Example SensorGestureDetector:
http://code.google.com/p/openintents/source/browse/trunk/ShoppingList/src/org/openintents/hardware/SensorGestureDetector.java?r=1106)
, then which of the 2 ways u suggest me to use:

1) we use it the way we use GestureDetector, extending
itsonSimpleGestureListener and implementig only the gestures specific
to the application. This is simple and straight
2) we have a service to which application can bind and the service
will call back when the getsure happens to the application which has
been binded. So this service will listen to the sensor events in 1st
place and implement the SensorGestureDetectors listeners which in turn
would call the applications method and then the application can decide
what to do on that specific gesture.

Thanks and Regards,
Learning_Android.

--~--~---------~--~----~------------~-------~--~----~

2. regarding android screenshot source code

hello..

we are trying to use the screen shot source code in our project, we
tried to compile screenshot code on eclipse, there is a "write"
function used which uses "renderd image" as one of its  parameter ,
but the one which is being passed is "buffered image", and we are
getting an error ..


so kinldy help in this regard.

--~--~---------~--~----~------------~-------~--~----~

3. Browser, videoo, plugins ... why is it not so ?

4. Accessing contact' email addresses

5. Is there a Color Picker widget in Android?

6. Adding Sensor Events as i/p and right way to use SensorGestureDetector

7. Android and Java Security Running Together