RE: [android-developers] Re: List of all instantiated Activities

2010-06-03 Thread Ted Neward
Assume I have an app that, although 95% of the time it will be used by a
single user, will occasionally be passed to a supervisor or somebody similar
who will do a logout/login/do-some-activity/logout cycle before handing it
back to the original employee using the device. On a logout, I'd like to
kill/finish all the running activities (allowing them to do their cleanup),
then essentially start fresh without having to litter all the activities
with calls to specifically test to see if we've done a logout since the last
time we were brought to the front of the user's attention.

Alternatively, I could just kill the process (I'm assuming a System.exit()
works), but that would have the undesirable effect of bringing the user back
to the Home screen and forcing them to select the app, which from a UX
perspective feels awkward and amateurish.

There's also the diagnostician in me that wants to be able to find all open
Activities and finish() them if we get a low-memory signal, but that's
really a distant second to the above use case.

Ted Neward
Java, .NET, XML Services
Consulting, Teaching, Speaking, Writing
http://www.tedneward.com

 -Original Message-
 From: android-developers@googlegroups.com [mailto:android-
 develop...@googlegroups.com] On Behalf Of Romain Guy
 Sent: Wednesday, June 02, 2010 1:26 AM
 To: android-developers@googlegroups.com
 Subject: Re: [android-developers] Re: List of all instantiated
 Activities
 
 Let's step back a little bit. Ted, what is it you are trying to do?
 
 On Wed, Jun 2, 2010 at 1:24 AM, Guillaume Perrot
 guillaume.p...@gmail.com wrote:
  I already made something similar (limited to the current activity)
 and
  I did not find another way to access the activity instance.
  To limit errors, I made my modifications in life cycle callbacks and
  users have to inherit my Activity classes (I made a full set for
  convenience, there are 9 Activity types) instead of the standard
 ones.
  You could place your code in onCreate, if they inherit your class
 they
  can't miss it.
  Of course the developer still have to ensure it does not miss an
  inheritance change but it's easier than adding a snippet of code
  everywhere and more object friendly.
 
  On 2 juin, 08:35, Ted Neward ted.new...@gmail.com wrote:
  Anybody know an easy way for an app to find all the instances of all
 the
  Activities currently alive in the current process?
 
  Yes, I could register each one into a static List someplace from
 the
  constructor of each Activity, but that requires developers to
 remember to
  put that code into every Activity constructor, which is going to
 eventually
  miss one or two (not to mention keep the Activity alive longer than
 it
  should be, though that could be fixed by holding WeakReferences
 instead of
  strong ones, but that still misses the point), and that's going to
 mean one
  or two escape the list. I'd prefer to have a way to see all of them
 from
  Android's/Dalvik's point of view.
 
  Ted Neward
 
  Java, .NET, XML Services
 
  Consulting, Teaching, Speaking, Writing
 
   http://www.tedneward.comhttp://www.tedneward.com
 
  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-
 develop...@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
 
 
 
 
 --
 Romain Guy
 Android framework engineer
 romain...@android.com
 
 Note: please don't send private questions to me, as I don't have time
 to provide private support.  All such questions should be posted on
 public forums, where I and others can see and answer them
 
 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-
 develop...@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 at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: List of all instantiated Activities

2010-06-03 Thread Rajiv
You can implement this in your application by using following way:
1) You need a class that handle all the application (Say Handller)
 In Handller class you can create a method that create List and add list
into it.
 For example
 Class Handller{
  List list;
  //Some Housekeeping
  setActiveActivity(Activity activity){
   if(list.equals(null)){
//create list
   }
   else{
list.add(activity)
   }
  }
  List getActivity(){
   return list;
  }

 }
2) You need an Activity (say ActiveActivity) that extends Activity
 ex:
  public class ActiveActivity extends Activity {
 protected void onResume() {
 super.onResume();

 Handller.setActiveActivity(this);  //you need to take an instance
of Handler Class.
 }
 }

3) Now you can add all your activity in list by extending ActiveActivity.
 ex.
 public class ActivityA extends ActiveActivity {
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(...);
 }
4) You can get All Activities by using Handler getActivity().



Regards,
Rajiv

On Thu, Jun 3, 2010 at 2:39 PM, Ted Neward ted.new...@gmail.com wrote:

 Assume I have an app that, although 95% of the time it will be used by a
 single user, will occasionally be passed to a supervisor or somebody
 similar
 who will do a logout/login/do-some-activity/logout cycle before handing it
 back to the original employee using the device. On a logout, I'd like to
 kill/finish all the running activities (allowing them to do their cleanup),
 then essentially start fresh without having to litter all the activities
 with calls to specifically test to see if we've done a logout since the
 last
 time we were brought to the front of the user's attention.

 Alternatively, I could just kill the process (I'm assuming a System.exit()
 works), but that would have the undesirable effect of bringing the user
 back
 to the Home screen and forcing them to select the app, which from a UX
 perspective feels awkward and amateurish.

 There's also the diagnostician in me that wants to be able to find all open
 Activities and finish() them if we get a low-memory signal, but that's
 really a distant second to the above use case.

 Ted Neward
 Java, .NET, XML Services
 Consulting, Teaching, Speaking, Writing
 http://www.tedneward.com

   -Original Message-
  From: android-developers@googlegroups.com [mailto:android-
  develop...@googlegroups.com] On Behalf Of Romain Guy
  Sent: Wednesday, June 02, 2010 1:26 AM
  To: android-developers@googlegroups.com
  Subject: Re: [android-developers] Re: List of all instantiated
  Activities
 
  Let's step back a little bit. Ted, what is it you are trying to do?
 
  On Wed, Jun 2, 2010 at 1:24 AM, Guillaume Perrot
  guillaume.p...@gmail.com wrote:
   I already made something similar (limited to the current activity)
  and
   I did not find another way to access the activity instance.
   To limit errors, I made my modifications in life cycle callbacks and
   users have to inherit my Activity classes (I made a full set for
   convenience, there are 9 Activity types) instead of the standard
  ones.
   You could place your code in onCreate, if they inherit your class
  they
   can't miss it.
   Of course the developer still have to ensure it does not miss an
   inheritance change but it's easier than adding a snippet of code
   everywhere and more object friendly.
  
   On 2 juin, 08:35, Ted Neward ted.new...@gmail.com wrote:
   Anybody know an easy way for an app to find all the instances of all
  the
   Activities currently alive in the current process?
  
   Yes, I could register each one into a static List someplace from
  the
   constructor of each Activity, but that requires developers to
  remember to
   put that code into every Activity constructor, which is going to
  eventually
   miss one or two (not to mention keep the Activity alive longer than
  it
   should be, though that could be fixed by holding WeakReferences
  instead of
   strong ones, but that still misses the point), and that's going to
  mean one
   or two escape the list. I'd prefer to have a way to see all of them
  from
   Android's/Dalvik's point of view.
  
   Ted Neward
  
   Java, .NET, XML Services
  
   Consulting, Teaching, Speaking, Writing
  
http://www.tedneward.comhttp://www.tedneward.com
  
   --
   You received this message because you are subscribed to the Google
   Groups Android Developers group.
   To post to this group, send email to android-
  develop...@googlegroups.com
   To unsubscribe from this group, send email to
   android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
   For more options, visit this group at
   http://groups.google.com/group/android-developers?hl=en
  
 
 
 
  --
  Romain Guy
  Android framework engineer
  romain...@android.com
 
  Note: please don't send private questions to me, as I don't have time
  to provide private support.  All

RE: [android-developers] Re: List of all instantiated Activities

2010-06-03 Thread Ted Neward
I could do what you're suggesting (which I already said I didn't want to do)
much more simply from within a default constructor:

 

public class RegisteredActivity extends Activity

{

  public static ListActivity getAllActivities() { 

// make sure clients can't modify the contents

return Collections.unmodifiableList(theList);

  }

  private static ListActivity theList = new ArrayListActivity();

 

  public RegisteredActivity() { super(); theList.add(this); }

}

 

Since the common path here is to have Activities that don't explicitly
provide a constructor, the default constructor synthesized by the compiler
will call the parent's default constructor, thus making it trivial for
people to use this-they just create an Activity that inherits from my
RegisteredActivity instead of from Activity. But that would still require me
to create subclasses of every Activity type that other developers might want
to subclass, and it still requires developers to subclass my
RegisteredActivity, which means that it's inevitable that somebody won't do
that (by mistake), and lo, I've got an Activity out there that isn't caught
up in my List.

 

All of which I already mentioned in my first post-I don't want to do it this
way. It's error-prone. I was hoping for an API call at the Android level
that would return this list for me.

 

Ted Neward

Java, .NET, XML Services

Consulting, Teaching, Speaking, Writing

http://www.tedneward.com

 

 

From: android-developers@googlegroups.com
[mailto:android-develop...@googlegroups.com] On Behalf Of Rajiv
Sent: Thursday, June 03, 2010 4:05 AM
To: android-developers@googlegroups.com
Subject: Re: [android-developers] Re: List of all instantiated Activities

 

 

You can implement this in your application by using following way:

1) You need a class that handle all the application (Say Handller)
 In Handller class you can create a method that create List and add list
into it.
 For example 
 Class Handller{
  List list;
  //Some Housekeeping
  setActiveActivity(Activity activity){
   if(list.equals(null)){
//create list
   }
   else{
list.add(activity)
   }
  }
  List getActivity(){
   return list;
  }
  
 }

2) You need an Activity (say ActiveActivity) that extends Activity
 ex:
  public class ActiveActivity extends Activity {
 protected void onResume() {
 super.onResume();
  
 Handller.setActiveActivity(this);  //you need to take an instance
of Handler Class.
 }
 }
 
3) Now you can add all your activity in list by extending ActiveActivity.
 ex.
 public class ActivityA extends ActiveActivity {
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(...);
 }

4) You can get All Activities by using Handler getActivity().
 

 

 

Regards,

Rajiv

On Thu, Jun 3, 2010 at 2:39 PM, Ted Neward ted.new...@gmail.com wrote:

Assume I have an app that, although 95% of the time it will be used by a
single user, will occasionally be passed to a supervisor or somebody similar
who will do a logout/login/do-some-activity/logout cycle before handing it
back to the original employee using the device. On a logout, I'd like to
kill/finish all the running activities (allowing them to do their cleanup),
then essentially start fresh without having to litter all the activities
with calls to specifically test to see if we've done a logout since the last
time we were brought to the front of the user's attention.

Alternatively, I could just kill the process (I'm assuming a System.exit()
works), but that would have the undesirable effect of bringing the user back
to the Home screen and forcing them to select the app, which from a UX
perspective feels awkward and amateurish.

There's also the diagnostician in me that wants to be able to find all open
Activities and finish() them if we get a low-memory signal, but that's
really a distant second to the above use case.


Ted Neward
Java, .NET, XML Services
Consulting, Teaching, Speaking, Writing
http://www.tedneward.com http://www.tedneward.com/ 

 -Original Message-
 From: android-developers@googlegroups.com [mailto:android-
 develop...@googlegroups.com] On Behalf Of Romain Guy
 Sent: Wednesday, June 02, 2010 1:26 AM
 To: android-developers@googlegroups.com
 Subject: Re: [android-developers] Re: List of all instantiated
 Activities

 Let's step back a little bit. Ted, what is it you are trying to do?

 On Wed, Jun 2, 2010 at 1:24 AM, Guillaume Perrot
 guillaume.p...@gmail.com wrote:
  I already made something similar (limited to the current activity)
 and
  I did not find another way to access the activity instance.
  To limit errors, I made my modifications in life cycle callbacks and
  users have to inherit my Activity classes (I made a full set for
  convenience, there are 9 Activity types) instead of the standard
 ones.
  You could place your code in onCreate, if they inherit your class
 they
  can't miss it.
  Of course the developer still

Re: [android-developers] Re: List of all instantiated Activities

2010-06-02 Thread Romain Guy
Let's step back a little bit. Ted, what is it you are trying to do?

On Wed, Jun 2, 2010 at 1:24 AM, Guillaume Perrot
guillaume.p...@gmail.com wrote:
 I already made something similar (limited to the current activity) and
 I did not find another way to access the activity instance.
 To limit errors, I made my modifications in life cycle callbacks and
 users have to inherit my Activity classes (I made a full set for
 convenience, there are 9 Activity types) instead of the standard ones.
 You could place your code in onCreate, if they inherit your class they
 can't miss it.
 Of course the developer still have to ensure it does not miss an
 inheritance change but it's easier than adding a snippet of code
 everywhere and more object friendly.

 On 2 juin, 08:35, Ted Neward ted.new...@gmail.com wrote:
 Anybody know an easy way for an app to find all the instances of all the
 Activities currently alive in the current process?

 Yes, I could register each one into a static List someplace from the
 constructor of each Activity, but that requires developers to remember to
 put that code into every Activity constructor, which is going to eventually
 miss one or two (not to mention keep the Activity alive longer than it
 should be, though that could be fixed by holding WeakReferences instead of
 strong ones, but that still misses the point), and that's going to mean one
 or two escape the list. I'd prefer to have a way to see all of them from
 Android's/Dalvik's point of view.

 Ted Neward

 Java, .NET, XML Services

 Consulting, Teaching, Speaking, Writing

  http://www.tedneward.comhttp://www.tedneward.com

 --
 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




-- 
Romain Guy
Android framework engineer
romain...@android.com

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

-- 
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: List of all instantiated Activities

2010-06-02 Thread Romain Guy
getInstanceCount() is there for debugging purpose and is not reliable.

On Wed, Jun 2, 2010 at 2:14 AM, skink psk...@gmail.com wrote:


 On Jun 2, 4:35 am, Ted Neward ted.new...@gmail.com wrote:
 Anybody know an easy way for an app to find all the instances of all the
 Activities currently alive in the current process?


 afaik, you can't do this

 you can however get total #Activities by calling Activity's static
 method getInstanceCount()

 pskink

 --
 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




-- 
Romain Guy
Android framework engineer
romain...@android.com

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

-- 
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: List of all instantiated Activities

2010-06-02 Thread Romain Guy
Because it's implemented using finalize(). And in Froyo this will
always return 0 btw.

On Wed, Jun 2, 2010 at 2:25 AM, skink psk...@gmail.com wrote:


 On Jun 2, 7:16 am, Romain Guy romain...@android.com wrote:
 getInstanceCount() is there for debugging purpose and is not reliable.



 why is it not reliable?

 pskink

 --
 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




-- 
Romain Guy
Android framework engineer
romain...@android.com

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

-- 
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