I want to show an alert dialog when booting of device is completed. There are no problems with the broadcast receiver, it works fine. But when boot is completed, there is no open activity, hence I get NullPointerException
here. How can I show a dialog box in this situation? This is the code I use to show the dialog:
public class RestartReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
AlertDialog alertHelp;
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
TextView m_timetext = new TextView(context );
m_timetext.setText("hello");
// m_timetext.setTextColor(getResources().getColor(R.color.dark_green));
LinearLayout linearLayout = new LinearLayout(context );
linearLayout.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
linearLayout.setOrientation(1);
linearLayout.addView(m_timetext);
dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}});
dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}});
alertHelp = dialog.create();
alertHelp.setView(linearLayout);
alertHelp.show();
Log.d("In","Switched On");
}
}
Please help me. Thanks in advance.