How to inform an Activity that another Activity was just started?

Finally, I found a solution, use IActivityWatcher and ActivityManagerNative, and build in source code Thank T3Roar very much, I just follow your clue to find this sample code below: package zouyu.sample. Activitymonitor; import android.app. Activity; import android.app.

ActivityManagerNative; import android.app. IActivityWatcher; import android.os. Bundle; import android.os.

RemoteException; import android.util. Log; public class ActivityMonitor extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.

OnCreate(savedInstanceState); setContentView(R.layout. Main); try { ActivityManagerNative.getDefault(). RegisterActivityWatcher(mActivityWatcher); } catch (RemoteException e) { } } private IActivityWatcher.

Stub mActivityWatcher = new IActivityWatcher.Stub() { public void activityResuming(int activityId) throws RemoteException { Log. E("zouyu", "In ActivityMonitor, an Activity resuming: " + activityId); } public void closingSystemDialogs(String reason) { Log. E("zouyu", "In ActivityMonitor, an Activity closing: " + reason); } }; }.

Finally, I found a solution, use IActivityWatcher and ActivityManagerNative, and build in source code. Thank T3Roar very much, I just follow your clue to find this. Sample code below: package zouyu.sample.

Activitymonitor; import android.app. Activity; import android.app. ActivityManagerNative; import android.app.

IActivityWatcher; import android.os. Bundle; import android.os. RemoteException; import android.util.

Log; public class ActivityMonitor extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super. OnCreate(savedInstanceState); setContentView(R.layout.

Main); try { ActivityManagerNative.getDefault(). RegisterActivityWatcher(mActivityWatcher); } catch (RemoteException e) { } } private IActivityWatcher. Stub mActivityWatcher = new IActivityWatcher.Stub() { public void activityResuming(int activityId) throws RemoteException { Log.

E("zouyu", "In ActivityMonitor, an Activity resuming: " + activityId); } public void closingSystemDialogs(String reason) { Log. E("zouyu", "In ActivityMonitor, an Activity closing: " + reason); } }; }.

You have the activity life cycle methods to know when they are created and when they are resumed, etc. Not sure if you mean when it is created (onCreate) or when it is resumed or comes back into focus (onResume). Personally, I'd sub-class Activity and Application.To sub-class application, you have to remember to declare the class name of the Application in your manifest. The application can have a HashMap keyed by Activity names with an int value of the number of times each activity is resumed or created (or whatever you want).

All your activities currently derive from the Activity class.So, you could create your own ActivityBase that extends Activity and adds overriden methods for onCreate and onResume. These overridden methods would call a method on the Application class to tell it to increment their count. Then, all your activities would extend ActivityBase instead of Activity.

It's very nice of you to give a so detailed and patient response! I think it must be a good method to count my own activities. But for my scenario, I need to count very Activities include others(like Activities of Gmail, Messaging, Browser, Facebook etc...).

So is there a common method for every activities? Thanks again for your help! – Yu Zou Mar 31 '10 at 3:29 Sorry it is not possible to do this.

– hackbod Mar 31 '10 at 5:51 I just find an app in market, named "Protector Demo". It can add a password check for some specified apps or activities, how could that be? I think my problem can use that method if we know how it works:D – Yu Zou Mar 31 '10 at 6:45.

I am certain it's possible since apps like Protector Demo are able to listen for applications opening. In the Android "Spare Parts" application (it's in the emulator, but probably not on any commercial phones), there is a section called "Usage Statistics". It records not only how many times applications were opened, but also how many milliseconds in total they've been open for.

I don't know how it would achieve that. My best guess would be to pull the information from the system, although other possibilities are an Intent listener or Broadcast Receiver. The source for Spare Parts is here, if you want to have a look: http://android.git.kernel.org/?p=platform/development.git;a=blob;f=apps/SpareParts/src/com/android/spare_parts/SpareParts.java;h=c00cc516a3aace20918113ef26b82367fde5a231;hb=HEAD.

Each activity is given a window in which to draw its user interface. To each other. Is presented to the user when launching the application for the first time.

Activity can then start another activity in order to perform different actions. In a stack (the "back stack"). Takes user focus.

Is popped from the stack (and destroyed) and the previous activity resumes. Through the activity's lifecycle callback methods. Appropriate to that state change.

Large objects, such as network or database connections.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions