Ich habe diese Frage früher gestellt here, aber niemand war in der Lage, diese auch zu beantworten. Das Problem ist, dass in meiner Tätigkeit onCreate ich einen Alarm Dialog erschaffe und diese Methode läuft perfekt auf Android 5.0, aber in Android API weniger als 5 Ich erhalte eine Fehlermeldung:Fehler: Launcherdialogabweisung ist fehlgeschlagen: java.lang.IllegalArgumentException
Logcat:
E/HwLauncher: Launcher dialog dismiss failed : java.lang.IllegalArgumentException: no dialog with id 1 was ever shown via Activity#showDialog
unten ist mein Code für die Aktivität
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
// Alert Box
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Internet not connected");
builder.setMessage("You need to connect WiFi/Mobile-Data run this app.");
builder.setCancelable(false);
builder.setPositiveButton(
"Go to Settings",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(Settings.ACTION_SETTINGS));
finish();
}
});
builder.setNegativeButton(
"Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
final AlertDialog alert = builder.create();
alert.show();
ConnectivityManager cm = (ConnectivityManager)
getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null){
alert.dismiss();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(splash.this, LoginActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
ich habe versucht, andere Antworten von Stackoverflow like this one aber keine dieser Antworten half mir
EDIT:
Ich habe den AlertDialog-Teil des Codes auskommentiert, aber der Fehler besteht immer noch. Unten ist der Code, den ich jetzt ohne bin mit Alertdialog
public class splash extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(splash.this, LoginActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
// Alert Box
/*
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Internet not connected");
builder.setMessage("You need to connect WiFi/Mobile-Data run this app.");
builder.setCancelable(false);
builder.setPositiveButton(
"Go to Settings",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(Settings.ACTION_SETTINGS));
finish();
}
});
builder.setNegativeButton(
"Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
final Dialog alert = builder.create();
alert.show();
//WifiManager wifi =(WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
ConnectivityManager cm = (ConnectivityManager)
getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null){
alert.dismiss();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(splash.this, LoginActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}*/
}
Auch mit dem Alertdialog aus Logcat kommentiert zeigt den gleichen Fehler:
Launcher dialog dismiss failed : java.lang.IllegalArgumentException: no dialog with id 1 was ever shown via Activity#showDialog
insted AlertDilaog der Verwendung versuchen, nur letzten Dialog alert = builder.create Verwendung(); –
https://StackOverflow.com/Questions/5815089/android-illegalargumentException-for-Dismissdialog –
@Manojkumar Ich versuchte diese Lösung, aber der Fehler ist immer noch der gleiche –