I'm a new to android, so I'm trying to develop an application that shows a notification to the user after specific time, I don't know: Is it possible to use a dialog box inside Service ! or not !...
My Goal is: to ask him a question after specific time, as shown below in my code,
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
}
});
}
}
Also I don't know shall I use Service or BroadcastReceiver ??
any suggestion, thanks in advance =)