我想在IntentService
類的onHandleIntent()
方法打開自定義對話框,但是當我爲表示該方法對話框編寫代碼,它顯示錯誤「的方法findViewById( int)未定義爲類型MyAlarmService「。任何人都可以建議我如何解決這個問題。如何onHandleIntent打開對話框()的IntentService類的方法
代碼我已經使用
public class MyAlarmService extends IntentService
{
public void onCreate()
{
super.onCreate();
}
public MyAlarmService()
{
super("MyAlarmService");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
super.onStartCommand(intent, startId, startId);
Toast.makeText(this, "MyAlarmService.onStart()", Toast.LENGTH_LONG).show();
return START_STICKY;
}
@SuppressWarnings("static-access")
@Override
protected void onHandleIntent(Intent intent)
{
final Dialog alarmDialog = new Dialog(MyAlarmService.this);
alarmDialog .requestWindowFeature(alarmDialog.getWindow().FEATURE_NO_TITLE);
alarmDialog .getWindow().setBackgroundDrawable(new ColorDrawable(0));
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.clear_all_warning_dialog, (ViewGroup) findViewById(R.id.layout_warning_dialog));
TextView dialogTitile = (TextView) layout.findViewById(R.id.dialog_title_text);
TextView dialogDesc = (TextView) layout.findViewById(R.id.dialog_desc_text);
Button buttonYes = (Button) layout.findViewById(R.id.button_yes);
Button buttonNo = (Button) layout.findViewById(R.id.button_no);
alarmDialog.setContentView(layout);
alarmDialog.show();
buttonYes.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
alarmDialog.dismiss();
}
});
buttonNo.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
alarmDialog.dismiss();
}
});
}
}
它可以顯示服務的對話? –
但在我的情況下,我不得不使用IntentService類,所以你知道如何在IntentService類中顯示對話框。其次,如果我使用服務類我的應用程序總是顯示在運行過程,而不是緩存過程 – AndroidDev