我是初学者,最近看到了下面的代码:
public class ActivityCollector {
public static List<Activity> activities = new ArrayList<Activity>();
public static void addActivity(Activity activity) {
activities.add(activity);
}
public static void removeActivity(Activity activity) {
activities.remove(activity);
}
}
另一个class:
public class BaseActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityCollector.addActivity(this);
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
ActivityCollector.removeActivity(this);
}
想请问一下,ActivityCollector不是类名吗?可以被直接引用吗?不是应该先定义一个对象,然后引用对象吗?像这样: ActivityCollector A; A.addActivity(this);
谢谢解答!