我是一个新的android,所以我试图开发一个应用程序,在特定的时间之后向用户显示通知,我不知道:是否可以在服务中使用对话框! !或不...是否可以在Service [android app]中显示对话框?
我的目标是:要问他后特定时间的问题,因为在我的代码如下所示,
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
}
});
}
}
此外,我不知道我将使用服务或广播接收器? ?
任何建议,提前感谢=)
谢谢你,但是我没有把你好,请你多解释一下,谢谢。 =') – Samiah 2012-03-12 16:54:44
如果我创建一个活动,然后调用broadcastRecevier,并调用服务如何使服务调用基本活动+我怎样才能让活动显示dialogAlert,而无需按任何按钮,! – Samiah 2012-03-12 17:01:40
不是你的活动会打电话给BroadcastReciever。 BroadcastReceiver将由Android调用。然后从您的广播接收器调用服务和服务将调用您的活动。详细了解广播接收者的工作原理 – 2012-03-15 06:53:45