Android Intent上下文混淆

7 浏览
0 Comments

Android Intent上下文混淆

请问有人能解释给我听吗:

Intent intent = new Intent(Context, AlarmReceiver.class);

如果没有人试着深入解释给我听,我永远都不会明白,这个上下文的东西对我来说太困惑了。有时候它的用法是这样的:

Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);

有时候不是这样,而是这样:

Intent intent = new Intent(context, AlarmReceiver.class);

有时候是这样的:

Intent intent = new Intent(this, AlarmReceiver.class);

等等,还有其他很多情况。

我理解上下文的基本概念,但有多少个上下文?为什么Eclipse有时会报错,而有时又没问题?为什么有时候我们需要声明上下文:

Context context;

我找不到适用于所有情况的正确上下文,我怎么知道每个情况下应该使用哪个上下文?

0