2012-04-12 2 views
0

У меня есть будильник в приложении, который уведомляет меня каждые 10 минут. Он работает нормально, но каждый раз, когда будильник уведомляет меня, мое имя приложения отображается как окно в середине экрана, и я не могу нажать ничего, пока не нажмем кнопку «Назад». Это действительно странно!Ошибка приложения, вызывающая странную ошибку, до тех пор, пока я не нажму кнопку возврата

Вот мой код:

// Alert Code 
    final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); 
    alertDialog.setTitle("Confirmation"); 
    alertDialog.setMessage("Are you sure you want to send this report?"); 
    run(gotDataS); 

    // Timer Code 
    pendingIntent = PendingIntent.getService(CreateNewForm_3.this, 0, 
      new Intent(NewForm_3.this, MyAlarmService.class), 0); 
    Send.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      alertDialog.setButton("OK", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, 
             int which) { 

         Toast.makeText(NewForm_3.this, "Sent", 0) 
           .show(); 

         long firstTime = SystemClock.elapsedRealtime(); 
         am = (AlarmManager) getSystemService(ALARM_SERVICE); 
         am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 
           firstTime + 10 * 1000, 30 * 1000, pendingIntent); 
         // firstTime Will be the current_time + (10 * 60 * 1000) =) 
         // 10* 1000 will be (10 * 60 * 1000) 
         new Handler().postDelayed(new Runnable() { 
          public void run() { 
           bCancel.performClick(); 
          } 
         }, (30 * 1000)); 
         // (30 * 1000) will be firstTime + (2- duration) 

         Intent toRecentCases = new Intent(CreateNewForm_3.this, 
           LMPActivity.class); 
         startActivity(toRecentCases); 
        } 
       }); 

      alertDialog.setButton2("No", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, 
          int which) { 
         // Here you can add functions 
        } 
       }); 

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

    }); 


    bCancel.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      am.cancel(pendingIntent); 
     } 
    }); 

    //For Notification -3- 
    final AlertDialog alertDialog3 = new AlertDialog.Builder(this).create(); 
    alertDialog3.setTitle("Confirmation"); 
    alertDialog3.setMessage("Are you sure you want to quite?"); 

    // Press cancel button it will move user to actvity p 
    Cancelb.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      alertDialog3.setButton("OK", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, 
          int which) { 

         Intent toRecentCases = new Intent(NewForm_3.this, 
                  LMPActivity.class); 
         startActivity(toRecentCases); 
        } 
       }); 

      alertDialog3.setButton2("No", 
        new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, 
           int which) { 
          // Doing nothing! 
         } 
        }); 

      alertDialog3.setIcon(android.R.drawable.ic_dialog_alert); 
      alertDialog3.show(); 
     } 
    }); 

} 

Это показывает диалог активность

public class ShowingDialog extends Activity { 

    boolean b; 
    String CancelMsg; 

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

     //For Notification -1- 
     final AlertDialog alertDialog = new AlertDialog.Builder(this).create(); 
     alertDialog.setTitle("Confirmation"); 
     alertDialog.setMessage("Do you really want it?"); 

     // For Notification -2- 
     final AlertDialog alertDialog2 = new AlertDialog.Builder(this).create(); 
     alertDialog2.setTitle("Confirmation"); 
     alertDialog2.setMessage("Are you sure you want it?"); 

     alertDialog.setButton("yes", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int which) { 
       Intent intent= new Intent(ShowingDialog.this,MyPage.class); 
       startActivity(intent); 
      ; 
      } 
     }); 

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

        alertDialog2.setButton("yes", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          // Here you can add functions 
          // Sending a Message to server that the plaintiff found the case 
          // For Sending SMS with cancel Request 
          // Getting Case_ID + putting it inside CancelMsg 
           CancelMsg = "Case_ID cancel"; 
          if (!b) { 
           try { 
            sendSMS("5556", CancelMsg); 
            Toast.makeText(ShowingDialog.this, "Sent", Toast.LENGTH_LONG) 
              .show(); 
           } catch (Exception e) { 
            // TODO Auto-generated catch block 
            Toast.makeText(ShowingDialog.this, e.getMessage(), 
              Toast.LENGTH_LONG).show(); 
           } 
          } 
         } 
        }); 

        alertDialog2.setButton2("no", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int which) { 
          // Here you can add functions 
          // Do nothing 
         } 
        }); 

        alertDialog2.setIcon(android.R.drawable.ic_dialog_alert); 
        alertDialog2.show(); 
       } 
      }); 

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

     public void sendSMS(String number, String msg) throws Exception { 
      if (!b) { 
       SmsManager smsManager = SmsManager.getDefault(); 
       smsManager.sendTextMessage(number, null, msg, null, null); 
      } 
      b = true; 
     } 
    } 

В манифесте:

<activity 
    android:name=".ShowingDialog" 
    android:theme="@android:style/Theme.Dialog" /> 
+1

скриншот поможет лучше понять .. – Ronnie

+0

Что делает MyAlarmService делать, когда он получает от намерения вашей тревоги? – Jules

+0

показать мне активность в диалоговом окне, пожалуйста, проверьте обновление – Maha

ответ

2

Не похоже, что вы перегружаете задний оператор, поэтому, когда вы нажимаете кнопку «Назад», вы перемещаете резервную копию вашего Back Stack. Android документация содержит больше информации об этом:

Tasks and Back Stack

+0

На самом деле, я не понимаю? не могли бы вы предоставить мне код? Как я могу это сделать? – Maha

+0

Ожидание ответа на ур :) – Maha

+0

Это не наша работа, чтобы помочь вам. Будучи вежливым, вы получите гораздо больше помощи, чем кричите тем, кто дает вам советы. – Charles