[android-developers] Re: Is it possible to start an Activity from a non-context class?

2010-05-04 Thread Michael J
Misspoke in my original post.  The second paragraph should read:

... use the original activity to start the activity.  The problem
with this is that the RESULT is sent to the original activity,
rather than the utility class.

On May 4, 2:02 am, Michael J txaggiemich...@gmail.com 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.

 The only way I could think of starting the activity was to pass the
 original activity to the utility class, so that the utility class
 could use the original activity to start the activity.  The problem
 with this is that the activity is sent to the original activity,
 rather than the utility class.

 I also thought of actually making the utility class an activity
 itself, but that would make using the utility class much more
 complicated.

 Thanks for any advice!

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Is it possible to start an Activity from a non-context class?

2010-05-04 Thread Michael J


On May 4, 10:40 am, TreKing treking...@gmail.com wrote:
 Why are you doing this? What purpose is your utility class serving that it
 requires starting and retrieving data from another activity?

Here's the usage.  Let me know if there's a much easier way of doing
this.

In my application, I'm referencing a RESTful web service which
requires token authentication.  My utility class is simply a utility
for sending a REST request.  If the request responds with an invalid
authentication message, I would like the utility to be able to
initiate a LogIn activity to request a new authentication from the
user.  Once the LogIn activity has completed, I would like the utility
class to be able to handle the LogIn activity's result, and attempt
the request again.

On May 4, 10:42 am, Timo Prill timo.pr...@googlemail.com wrote:
 just pass your context over to the utility class via getter/setter or in
 constructor...

Like I said before, I tried this, but the problem is that the activity
result cannot be sent to the utility class, which is what I need.

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


[android-developers] Re: Is it possible to start an Activity from a non-context class?

2010-05-04 Thread Matt Kanninen
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 timo.pr...@googlemail.com 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 txaggiemich...@gmail.com
  mailto:txaggiemich...@gmail.com 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 android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.com
  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 android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Is it possible to start an Activity from a non-context class?

2010-05-04 Thread TreKing
On Tue, May 4, 2010 at 11:56 AM, Michael J txaggiemich...@gmail.com wrote:

 In my application, I'm referencing a RESTful web service which
 requires token authentication.  My utility class is simply a utility
 for sending a REST request.  If the request responds with an invalid
 authentication message, I would like the utility to be able to
 initiate a LogIn activity to request a new authentication from the
 user.  Once the LogIn activity has completed, I would like the utility
 class to be able to handle the LogIn activity's result, and attempt
 the request again.


It sounds to me like you're giving this utility class a responsibility it
should not have. If it's purpose is to send requests (and report back
errors) then that's all it should do.

I don't know how you've set up your code, but I would expect a main activity
that is responsible for doing the request using the utility class. If that
fails (which the utility class would report), the calling activity would
then launch the login activity to get the details, which you would get back
in onActivityResult, which the main activity would then pass on to the
utility class to try the request again.

Again, I don't know the details of your code, but I don't see why this class
would need to start and get results from an 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Is it possible to start an Activity from a non-context class?

2010-05-04 Thread Michael J
Yea, I've definitely considered that option.  I suppose my whole
reason for this is to avoid needing to handle an error from the
utility class in each of my activities.

My application is one main TabActivity that contains 4 tabs, each
being it's own activity.  You've made me realize that it might be
possible for me to have the activities request authentication from the
main TabActivity, which would be responsible for starting the login
activity.  In which case I would only need the main TabActivity to
handle the login activity's response.  Does this sound like a logical
design?

Sorry for being an idiot, I'm still trying to get a hold on the
Android framework...

On May 4, 12:25 pm, TreKing treking...@gmail.com wrote:
 On Tue, May 4, 2010 at 11:56 AM, Michael J txaggiemich...@gmail.com wrote:
  In my application, I'm referencing a RESTful web service which
  requires token authentication.  My utility class is simply a utility
  for sending a REST request.  If the request responds with an invalid
  authentication message, I would like the utility to be able to
  initiate a LogIn activity to request a new authentication from the
  user.  Once the LogIn activity has completed, I would like the utility
  class to be able to handle the LogIn activity's result, and attempt
  the request again.

 It sounds to me like you're giving this utility class a responsibility it
 should not have. If it's purpose is to send requests (and report back
 errors) then that's all it should do.

 I don't know how you've set up your code, but I would expect a main activity
 that is responsible for doing the request using the utility class. If that
 fails (which the utility class would report), the calling activity would
 then launch the login activity to get the details, which you would get back
 in onActivityResult, which the main activity would then pass on to the
 utility class to try the request again.

 Again, I don't know the details of your code, but I don't see why this class
 would need to start and get results from an activity.

 --- 
 --
 TreKing - Chicago transit tracking app for Android-powered 
 deviceshttp://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 android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Is it possible to start an Activity from a non-context class?

2010-05-04 Thread TreKing
On Tue, May 4, 2010 at 12:35 PM, Michael J txaggiemich...@gmail.com wrote:

 Does this sound like a logical design?


I haven't used Tabs, but from your description, yes. And it would surely be
better than what you were trying to do in the beginning.


 Sorry for being an idiot, I'm still trying to get a hold on the Android
 framework...


No apologies necessary - we're all here to learn.

-
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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en