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

这个问题的答案。这个返回值,可以等于给变量。

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.

你可能感兴趣的:(definition)