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. How to launch internal activity from PreferenceScreen

Hi,

Using PreferenceScreen in xml format we can launch activity by
specifying Intent as shown in sample application

<intent android:action="android.intent.action.VIEW"
                    android:data="http://www.android.com" />

This will launch Browser activity which is registered to handle http
protocol.


But I would like to launch my internal activity by explicitly
specifying it's name e.g.

<PreferenceScreen
                android:title="Internal activity"
                android:summary="This will launch internal activity
screen">
<intent android:name="com.myapp.MyInternalActivity"
                    android:data="mydata" />

</PreferenceScreen>


But this is not working. Getting exception of ActivityNotFound .

Am I missing anything ?


-- Tushar







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

2. Overview Of New Intel Core i7(Nehalem) Processor

Before entering on the details about the architectural features
present on the Nehalem CPUs, let make a summary of the base elements
that are common to the many different versions: server, desktop and
notebook. It worth noticing how the new architecture engineering
process used by Intel aims at obtaining CPUs that can be used in all
three sectors, by simply slightly changing architecture and CPU
characteristics to better adapt to each of the sectors.




for more info visit  http://www.intel-intel99.blogspot.com

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

3. Timeout using apache DefaultHttpClient not working when port is closed

4. Best way to add 100.000 words to database

5. Outlook Synchronization (Possible?)

6. 1.5 rebuild issue with emulator

7. OpenGL garbage collection (with direct ByteBuffers)