如何通知另一项活动是刚刚开始的活动? [英] How to inform an Activity that another Activity was just started?

查看:104
本文介绍了如何通知另一项活动是刚刚开始的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想获得的时间用于每项活动的号码。 所以很简单的方法,我认为是增加了计数的活动它启动时。但是,我怎么能得到这些信息?

I just want to get numbers of times to be used for each Activity. So the very straightforward method I thought is increasing the count for an Activity when it was started. But how can I get the information?

感谢您的帮助很大!

推荐答案

最后,我找到了一个解决方案,使用IActivityWatcher和ActivityManagerNative,并建立在源$ C ​​$ C。

Finally, I found a solution, use IActivityWatcher and ActivityManagerNative, and build in source code.

感谢T3Roar非常多,我只是按照你的线索,找到这一点。

Thank T3Roar very much, I just follow your clue to find this.

下面的示例code:

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);
        }
    };
}

这篇关于如何通知另一项活动是刚刚开始的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆