【发布时间】:2020-03-16 11:28:44
【问题描述】:
我最近开始使用 java,我试图了解“上下文”到底是什么,以及如何正确使用它。
public AdapterView.OnItemClickListener selectDevice = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
String info = ((TextView) view).getText().toString();
String adress = info.substring(info.length()-17);
Intent comIntent = new Intent(MainActivity.this, Communication.class); //WHY???
}
};
对于这个例子和 Intent 争论,我们为什么不使用“getContext()”或“getApplicationContext”或者只使用“this”?
【问题讨论】:
标签: java android android-intent anonymous-class