0

서비스에서 Broadcast을 보내고 BroadcastReceiver 클래스에서 서비스를 다시받습니다. 나는 약간의 논리를 기반으로 AlertDialog을 제시해야하지만, 그것을하는 동안, 나는이 런타임 오류 받고 있어요 : 나는 이것에 대한 인터넷을 검색하고 와서받기 '이 활동으로 Theme.AppCompat 테마 (또는 자손)를 사용해야합니다.' BroadcastReceiver에서 AlertDialog를 표시하려고 시도하는 동안

public class MyBroadcastReceiver extends BroadcastReceiver { 

     public MyBroadcastReceiver(){ 
      super(); 
     } 

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

      if (intent.getAction() != null && intent.getAction().equals(getString(R.string.broadcast_id))) { 

      Intent intent1 = new Intent(MyService.this, MainActivity.class); 
      intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      startActivity(intent1); 


        @Override 
        public void run() { 
         if (someCondition) { 

          android.support.v7.app.AlertDialog.Builder builder1 = new android.support.v7.app.AlertDialog.Builder(getBaseContext()); 
          builder1.setView(R.layout.dialog); 

          builder1.setPositiveButton(
            "OK", 
            new DialogInterface.OnClickListener() { 
             public void onClick(DialogInterface dialog, int id) { 
             Intent notificationIntent = new Intent(getBaseContext(), Notification.class); 
             notificationIntent.putExtra(Notification.NOTIFICATION, getNotificationGame()); 
             PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), m, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
             AlarmManager alarmManager = (AlarmManager) getBaseContext().getSystemService(Context.ALARM_SERVICE); 
             alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, finalFutureInMillis, pendingIntent); 
             postMethod(MainActivity.name, MainActivity.uidOfProfilePic, String.valueOf(MainActivity.currentLatDouble), String.valueOf(MainActivity.currentLngDouble), null, s, v, sA, requestID, user.getUid(), nP); 
              dialog.cancel(); 
             } 
            }); 

          final android.support.v7.app.AlertDialog alert11 = builder1.create(); 
          alert11.setCancelable(false); 
          alert11.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); 
          // error on line below 
          alert11.show(); 

          } 
         } 

      } 
     } 
    } 

: 여기 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

것은 MyBroadcastReceiver 클래스의 this은 활동을 생성하고 AlertDialog 코드를 제안하지만 사용자가 OK을 클릭하면 해당 코드가 Service에서 검색되고 다른 활동에서 액세스 할 수 없습니다. .

알려주십시오. 지금 어떻게해야합니까?

+0

활동에 어떤 유형의 테마를 사용합니까? 툴바를 사용합니까? – Diekrul

+0

@Diekrul이 활동에서 :'MainActivity.class'? 또는 broadcastreceiver는 무엇입니까? 왜냐하면이 방송 수신자는 서비스에 있고 질문에서 말한 활동이 아니기 때문입니다. –

답변

0

함마드 설명서에 따르면 에서 onReceive()를 구현할 때 팝업 대화 상자를 시작할 수 없다고합니다. (대답처럼) https://stackoverflow.com/a/4855397/7542998

수신자는 수신하여 새 프로세스를 시작합니다. 데이터 처리의 몇 초 후에 수신기가 시스템에 의해 막힐 수 있기 때문에, 당신이 그것에 어떤 논리를 넣었을 때 항상 염두에 두어야하기 때문에 그렇게 말합니다.

그러나, 같은 말이 다른 대답

(https://stackoverflow.com/a/16332260/7542998은)는 노 티피 케이션 API를 시도 할 수 있습니다.

두 링크 모두 원하는 결과를 얻을 수있는 좋은 대답이 있습니다.

희망이 도움이 될 것입니다.