简体   繁体   English

android活动类和对象

[英]android Activities classes and objects

I am new to android development.我是安卓开发的新手。 So I have a question about activities.所以我有一个关于活动的问题。 On Google developer, they say you have to make a class which is inheriting from the class Activity.在 Google 开发人员中,他们说您必须创建一个继承自 Activity 类的类。 So far so good.到现在为止还挺好。 Now I am thinking an Activity is a class, which leads to my major problem.现在我在想一个 Activity 是一个类,这导致了我的主要问题。 So when activity is a class how can it invoke all the live cycle methods.因此,当活动是一个类时,它如何调用所有实时循环方法。 In Java, I learnt there must be an object of a class to invoke methods and actions.在 Java 中,我了解到必须有一个类的对象来调用方法和操作。 So when activity is not an object but a class, how is this possible.所以当活动不是一个对象而是一个类时,这怎么可能。

Kindest regards Jan最亲切的问候 Jan

When a user starts your app the android operating system will instantiate an object based on your class which must be a subclass of Activity.当用户启动您的应用程序时,Android 操作系统将根据您的类实例化一个对象,该对象必须是 Activity 的子类。

The operating system will use that object and call the lifecycle hooks (eg onCreate, onResume, ...) which you implented in your activity subclass when one of the related lifecycle events happens.当相关生命周期事件之一发生时,操作系统将使用该对象并调用您在活动子类中实施的生命周期钩子(例如 onCreate、onResume 等)。

Here it is clearly mentioned under CREATING AN ACTIVITY header, that system calls the callback methods, based on which event has occurred. 这里在 CREATING AN ACTIVITY 标头下清楚地提到,系统根据发生的事件调用回调方法。 Suppose user is interacting with your activity, then using the object created by the OS for that activity, all the callback methods will be executed.假设用户正在与您的活动进行交互,然后使用操作系统为该活动创建的对象,所有回调方法都将被执行。 Please refer.请参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM