Showing AlertDialog when the Device is Locked
<p>I have to develop an application that shows an AlertDialog [Alarm] for each 10 minutes during 2 hour [Starting with time when the user clickd StartButton], Actually i typed this code it shows alertDialog but when I tested it on my mobile the AlertDialog don't appear when the mobile locked , however, I still have some issues,</p>

<p>This is my Code:-</p>

<pre><code>//Activity

public class AndroidAlarmService extends Activity {

private PendingIntent pendingIntent;


 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
     Button buttonStart = (Button)findViewById(R.id.startalarm);
     Button buttonCancel = (Button)findViewById(R.id.cancelalarm);

     buttonStart.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
         Intent myIntent = new Intent(AndroidAlarmService.this, BroadCastReceiverFor.class);
             pendingIntent = PendingIntent.getBroadcast(AndroidAlarmService.this, 234324243, myIntent, 0);

             Calendar calendar = Calendar.getInstance();
             calendar.setTimeInMillis(System.currentTimeMillis());
             calendar.add(Calendar.MINUTE, 10);       

             AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
             alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);



               Toast.makeText(AndroidAlarmService.this, "Start Alarm", Toast.LENGTH_LONG).show();
        }
    });

     buttonCancel.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
               AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
               alarmManager.cancel(pendingIntent);

                        // Tell the user about what we did.
                        Toast.makeText(AndroidAlarmService.this, "Cancel!", Toast.LENGTH_LONG).show();
        }
    });

 }

}
//BroadcastReceiver


public class BroadCastReceiverFor extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        Intent service = new Intent(context, MyAlarmService.class);
        context.startService(service);

    }
}

// Service

public class MyAlarmService extends Service { 

    @Override    

public void onCreate() {    
        // TODO Auto-generated method stub    
        Toast.makeText(this, "MyAlarmService.onCreate()", Toast.LENGTH_LONG)
        .show();      }    
    @Override  
    public IBinder onBind(Intent intent) { 
            // TODO Auto-generated method stub  
            Toast.makeText(this, "MyAlarmService.onBind()", Toast.LENGTH_LONG) 
            .show();         return null; 
            }   
        @Override 
        public void onDestroy() {   
            // TODO Auto-generated method stub   
            super.onDestroy();   
            Toast.makeText(this, "MyAlarmService.onDestroy()", Toast.LENGTH_LONG)  
            .show();     }  
        @Override
        public void onStart(Intent intent, int startId) {  
            // TODO Auto-generated method stub 
            super.onStart(intent, startId);  

            Toast.makeText(this, "MyAlarmService.onStart()", Toast.LENGTH_LONG).show(); 
            Intent dialog = new Intent(this, ShowingDialog.class);
            dialog.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
            startActivity(dialog);  

            }    
        @Override    
            public boolean onUnbind(Intent intent) 
            {         // TODO Auto-generated method stub    
                Toast.makeText(this, "MyAlarmService.onUnbind()", Toast.LENGTH_LONG)    
                .show();         return super.onUnbind(intent);     } 



} 


// Another Activity to show the AlertDialog


public class ShowingDialog extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        //For Notification

    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();

    //For Notification
            alertDialog.setTitle("Conformation");
            alertDialog.setMessage("Are you sure you want to Do that?");


                    alertDialog.setButton("Yes", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int which) {


                       }
                    });



                    alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                    alertDialog.show();

    }




}

// Manifest

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.exercise.AndroidAlarmService"
      android:versionCode="1"
      android:versionName="1.0"&gt;
    &lt;uses-sdk android:minSdkVersion="4" /&gt;

    &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
        &lt;activity android:name=".AndroidAlarmService"
                  android:label="@string/app_name"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;
                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;


    &lt;activity 
    android:name=".ShowingDialog"
     android:theme="@android:style/Theme.Dialog"/&gt; 


        &lt;service android:name=".MyAlarmService" /&gt;
        &lt;receiver android:name="BroadCastReceiverFor"&gt;&lt;/receiver&gt;

    &lt;/application&gt;
&lt;/manifest&gt;
</code></pre>

<p><strong>My Questions are:</strong></p>

<p>1- How can I make this alertDialog appear even when the device is locked?
2- How can I make the dialog appear again after 20 minutes ?</p>

<p>thanks in adavance..</p>
