從服務顯示警報對話時獲取異常。從服務顯示警報對話時獲取異常 - 無法添加窗口 - 令牌null不適用於應用程序
以下是我的服務類中的代碼:我試圖顯示AlertDialog。
但我得到的錯誤:無法添加窗口 - 令牌null不是一個應用程序
我還附上我的日誌的快照這個問題。
if(!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)&& !mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
Log.d("TrackingService","H: Exception after this");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Your GPS seems to be disabled, do you want to enable it?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
你無法控制的服務界面,你能做的最好的事情是開始一個新的活動,使它看起來像一個對話框。乾杯! – user2652394
@ user2652394這是否必須是一個活動,或者它可以只是一個XML佈局? –
是否有任何活動正在開始您的服務。 –