I have the following code:
package com.androidtest.notification;
import android.app.Activity;
import android.os.Bundle;
import android.widget;
import androi
Context in Activity is obtained by YourActivity.this or easier with this
package com.androidtest.notification;
import android.app.Activity;
import android.os.Bundle;
import android.widget;
import android.widget.Toast;
import android.content.Context;
public class ActivityNotification extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Context context = this; // or ActivityNotification.this
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(this, text, duration);
toast.show();
}
}
Short answer: add this
import android.content.Context;