Yeah thats what I usually do.  I'm also a fan of static methods that
get passed a Context object.  You can also have your application or
activities extend an interface, and have your methods expect that
interface.

The important thing is that your utility code trigger an execution
thread, with access to the right context.


I have a related question.  What are the consequences, and best
practices, of starting activities from a non activity context?  The
documentation says:

http://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent)
"
Note that if this method is being called from outside of an Activity
Context, then the Intent must include the FLAG_ACTIVITY_NEW_TASK
launch flag. This is because, without being started from an existing
Activity, there is no existing task in which to place the new activity
and thus it needs to be placed in its own separate task.
"
This seems to work, but I'm betting it has some interaction with
http://developer.android.com/guide/topics/manifest/activity-element.html
android:launchMode

but that already confuses me...

-MK


On May 4, 8:42 am, Timo Prill <[email protected]> wrote:
> just pass your context over to the utility class via getter/setter or in
> constructor...
>
> Am 04.05.2010 17:40, schrieb TreKing:
>
>
>
>
>
> > On Tue, May 4, 2010 at 2:02 AM, Michael J <[email protected]
> > <mailto:[email protected]>> wrote:
>
> >     For example, I have an activity that uses a utility class.  I
> >     would like to be able to start an activity from the utility class
> >     and have the activity result sent back to the utility class.
>
> > Why are you doing this? What purpose is your utility class serving
> > that it requires starting and retrieving data from another activity?
>
> > --------------------------------------------------------------------------- 
> > ----------------------
> > TreKing - Chicago transit tracking app for Android-powered devices
> >http://sites.google.com/site/rezmobileapps/treking
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to