definition

this / getActivity()

this is a reference to the current class you are in. It can be an Activity,Fragment,Adapter,View, etc. And when you use it what you are doing is just passing a reference of the current object of that class.

Let's say you are working on a customView. Anywhere in the code of that view where you callthiswill be interpreted as the View itself, so the value of this changes depending on what class you are in.

The method getActivity() is defined only in the Fragment class and any other class extending Fragment and this method returns and Object of the type Activity.

On Android development is very common mixing those two because most of the applications code is in Activity classes, and calling this on an Activity class will return anActivityobject but as you can see they are not the same thing.


static, and final

static - only one copy of this reference. a property of a whole class. all objs in this class have access to this value

final - can't change, can't reassigne. is a constant.


Context

?is a abs class.

Context is a interface to global 全局?info of the app envi.

Interface is a group of abs methods.

Context allows access to:

app resources, class

call for:launching activity, broadcasting, receiving intent


Activity

Activity is a Java code that supports a screen or UI.

activity extends context.

activity is a context.


Abstract class and interface

public abstract class Animal {

// instance variable

private double weight;

// getter

public double getWeight() {

return weight;

}

//abs method, no codes in curly braces, no curly braces.

public abstract void eat();

}

abs method, undefined, no codes in curly braces, no curly braces,

instance variable - class variable, to be defined in sub class

interface only contains abs methods and static final variable. no constructor.

abs class contains instance variable, abs method and setter, getters.


Context

Context is a abs class.

Context is a interface to global 全局?info of the app envi.

Interface is a group of abs methods.

Context allows access to:

app resources, class

call for:launching activity, broadcasting, receiving intent


Return

這個(gè)問題的答案。這個(gè)返回值,可以等于給變量。

return to whoever calls the method


Intent

intent is a tool to send and receive msg between activities.

Intent intent = new Intent (Context packageContext, Class);

= ship a Parcel parcel (address, receiver)

class is the class the receive it and start, pkgcontext is the pkg where the receiver class can be found.

intent.putExtra(String, boolean)

extra key-value pair

string is the key, it contains the pkg domain, so it tells which pkg the sender activity is from.

so that if there are multiple senders actuivity from different apps, you can tell.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容