I'm trying to detect whether the user has an Internet connection activated on their device, and if it's not connected to the Internet, it's supposed to take the user to the Settings app to activate wi-fi/mobile data.
if(!HelperFunctions.hasInternetAccess(this)){
Toast.makeText(this, "You are not connected to the Internet. Please connect to wi-fi or activate your mobile data.", Toast.LENGTH_LONG).show();
startActivity(new Intent(Settings.ACTION_SETTINGS));
}
However, I get this long litany of errors:
Activity com.[packageName].scanner.ReadCardActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@42c74c40 that was originally added here
android.view.WindowLeaked: Activity com.[packageName].scanner.ReadCardActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@42c74c40 that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:402)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:311)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
at android.view.Window$LocalWindowManager.addView(Window.java:554)
at android.app.Dialog.show(Dialog.java:277)
at android.app.AlertDialog$Builder.show(AlertDialog.java:932)
at com.touchtechpayments.scanner.ReadCardActivity.onCreate(ReadCardActivity.java:83)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
at android.app.ActivityThread.access$600(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
I've seen many solutions when it's a Dialog causing the problem, but nothing specific to Toasts. If it helps, that bit of code is in the onCreate() method, should it be in an AsyncTask or anything else instead?