Czy jest możliwe wywoływanie w usłudze okienka dialogowego. Stworzyłem osobną klase do dialogu dziedziczącą po Activity i jak chce później wywołać to okienko w service to się w ogóle nie pojawia.
public class dialog_window extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DialogWindow();
}
public void DialogWindow ()
{
Dialog dialog;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
//Okno dialogowe z własnym layoutem
Context context = getApplicationContext();
LayoutInflater inflater =
(LayoutInflater)context.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout =
inflater.inflate(R.layout.dialog_window,
(ViewGroup)findViewById(R.id.layout_root));
builder.setView(layout);
builder.setTitle("Enter PIN:");
//builder.setPositiveButton("OK", null);
builder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
} });
dialog = builder.create();
dialog.show();
}
}
public class serwis extends Service {
private Toast myToast;
public dialog_window window;
private Timer updatingTimer;
private TimerTask notify = new TimerTask() {
@Override
public void run() {
// myToast.setText("Usługa ciągle działa");
// myToast.show();
window.DialogWindow();
}
};
@Override
public void onCreate() {
super.onCreate();
updatingTimer = new Timer();
window=new dialog_window();
myToast = Toast.makeText(getApplicationContext(),
"Service enabled",
Toast.LENGTH_SHORT);
myToast.show();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
updatingTimer.scheduleAtFixedRate(notify, 8*1000, 8*1000);
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onDestroy() {
updatingTimer.cancel();
myToast.setText("Service disabled");
myToast.show();
super.onDestroy();
}
}
Nie chce uruchamiać całego okna bo nie ma takiej potrzeby. Dlatego dialog był by najlepszym rozwiązaniem.