Я новичок в Android, поэтому я пытаюсь разработать приложение, которое показывает уведомление пользователю через определенное время, я не знаю: возможно ли использовать диалоговое окно внутри Сервиса! или нет! ...
Моя цель: задать ему вопрос через определенное время, как показано ниже в моем коде,
import android.app.AlertDialog;
import android.app.Service;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class MyAlarmService extends Service {
@Override
public void onCreate() {
Toast.makeText(this, "MyAlarmService.onCreate()", Toast.LENGTH_LONG)
.show();
}
@Override
public IBinder onBind(Intent intent) {
Toast.makeText(this, "MyAlarmService.onBind()", Toast.LENGTH_LONG)
.show();
return null;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "MyAlarmService.onDestroy()", Toast.LENGTH_LONG)
.show();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Toast.makeText(this, "MyAlarmService.onStart()", Toast.LENGTH_LONG)
.show();
// For Notification
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Conformation");
alertDialog
.setMessage("Are you sure you want to Expand Report Region?");
alertDialog.setButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Sending a Message to server that the plaintiff wants to
// expand report region
}
});
alertDialog.setButton2("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
});
}
}
Также я не знаю, использовать ли мне Service или BroadcastReceiver ??
любое предложение, спасибо заранее =)