Skip to main content
replaced deprecated tag [context] by [android-context]
Source Link

About Android:About context

I paste some piece of my code here:

public void onCreate(Bundle savedInstanceState) {
        Log.e("Main Activity", "OnCreate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_frame);

        //GlowEffect is the custom class's constructor:GlowEffect(context);
        new GlowEffect2(getApplictionContext());

        AlertDialog.Builder builder = new Builder(this);
...
...

I find that when I change the param in **Builder(this)** to Builder(getApplicationContext()); The app will crash! While the GlowEffect2 constructor works well whatever the param is "this" or "getApplicationContext()". SOSo what the difference between the two params? Thanks in advance!

Android:About context

I paste some piece of my code here:

public void onCreate(Bundle savedInstanceState) {
        Log.e("Main Activity", "OnCreate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_frame);

        //GlowEffect is the custom class's constructor:GlowEffect(context);
        new GlowEffect2(getApplictionContext());

        AlertDialog.Builder builder = new Builder(this);
...
...

I find that when I change the param in **Builder(this)** to Builder(getApplicationContext()); The app will crash! While the GlowEffect2 constructor works well whatever the param is "this" or "getApplicationContext()". SO what the difference between the two params? Thanks in advance!

About Android context

I paste some piece of my code here:

public void onCreate(Bundle savedInstanceState) {
        Log.e("Main Activity", "OnCreate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_frame);

        //GlowEffect is the custom class's constructor:GlowEffect(context);
        new GlowEffect2(getApplictionContext());

        AlertDialog.Builder builder = new Builder(this);
...
...

I find that when I change the param in **Builder(this)** to Builder(getApplicationContext()); The app will crash! While the GlowEffect2 constructor works well whatever the param is "this" or "getApplicationContext()". So what the difference between the two params?

Source Link
Rocky
  • 1.3k
  • 3
  • 15
  • 37

Android:About context

I paste some piece of my code here:

public void onCreate(Bundle savedInstanceState) {
        Log.e("Main Activity", "OnCreate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_frame);

        //GlowEffect is the custom class's constructor:GlowEffect(context);
        new GlowEffect2(getApplictionContext());

        AlertDialog.Builder builder = new Builder(this);
...
...

I find that when I change the param in **Builder(this)** to Builder(getApplicationContext()); The app will crash! While the GlowEffect2 constructor works well whatever the param is "this" or "getApplicationContext()". SO what the difference between the two params? Thanks in advance!