I have a spinner that populates list of options properly at first. Then when I switch the activity and come back and tap the spinner the app crashes (see log below).
spinner1 = (Spinner) view.findViewById(R.id.fldWithSpinner1);
ArrayAdapter<?> aa = new ArrayAdapter<Object>(LocationsUI.this,
android.R.layout.simple_spinner_item,
availableLocations);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(aa);
Everytime when I switch to LocationsUI the spinner is created. The spinner works ok only at the first time LocationsUI is displayed, after that every time when I tap on the spinner after the LocationsUI is re-displayed, it would crash:
10-11 22:35:20.060: E/AndroidRuntime(30904): FATAL EXCEPTION: main
10-11 22:35:20.060: E/AndroidRuntime(30904): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy#407f6d50 is not valid; is your activity running?
10-11 22:35:20.060: E/AndroidRuntime(30904): at android.view.ViewRoot.setView(ViewRoot.java:538)
10-11 22:35:20.060: E/AndroidRuntime(30904): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:203)
10-11 22:35:20.060: E/AndroidRuntime(30904): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:117)
10-11 22:35:20.060: E/AndroidRuntime(30904): at android.view.Window$LocalWindowManager.addView(Window.java:424)
10-11 22:35:20.060: E/AndroidRuntime(30904): at android.app.Dialog.show(Dialog.java:241)
10-11 22:35:20.060: E/AndroidRuntime(30904): at android.app.AlertDialog$Builder.show(AlertDialog.java:823)
10-11 22:35:20.060: E/AndroidRuntime(30904): at android.widget.Spinner.performClick(Spinner.java:261)
10-11 22:35:20.060: E/AndroidRuntime(30904): at android.view.View$PerformClick.run(View.java:9249)
10-11 22:35:20.060: E/AndroidRuntime(30904): at android.os.Handler.handleCallback(Handler.java:587)
10-11 22:35:20.060: E/AndroidRuntime(30904): at android.os.Handler.dispatchMessage(Handler.java:92)
10-11 22:35:20.060: E/AndroidRuntime(30904): at android.os.Looper.loop(Looper.java:130)
10-11 22:35:20.060: E/AndroidRuntime(30904): at android.app.ActivityThread.main(ActivityThread.java:3691)
10-11 22:35:20.060: E/AndroidRuntime(30904): at java.lang.reflect.Method.invokeNative(Native Method)
10-11 22:35:20.060: E/AndroidRuntime(30904): at java.lang.reflect.Method.invoke(Method.java:507)
10-11 22:35:20.060: E/AndroidRuntime(30904): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
10-11 22:35:20.060: E/AndroidRuntime(30904): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
10-11 22:35:20.060: E/AndroidRuntime(30904): at dalvik.system.NativeStart.main(Native Method)
10-11 22:35:20.080: E/InputDispatcher(139): channel '40abf270 com.sw.android/com.sw.MyLocAppActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
10-11 22:35:20.080: E/InputDispatcher(139): channel '40abf270 com.sw.android/com.sw.MyLocAppActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
Can you please show me the right direction to fix this issue?
As your Logcat says : android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy#407f6d50 is not valid; is your activity running?
This can occur when you are showing the dialog for a context that no longer exists. Here is the link which can explain you what you doing wrong exactly : http://dimitar.me/android-displaying-dialogs-from-background-threads/
and here is the code that helps you from the same link :
private Handler myHandler = new Handler() {
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
case DISPLAY_DLG:
if (!isFinishing()) {
showDialog(MY_DIALOG);
}
break;
}
}
};
Related
The app is bloked only in last release test (Play Store) with:
google Pixel 5
1080x2340
Android 11 (SDK 30)
8.192 MB
arm64-v8a
es_ES
Before, in compilation with android studio all is ok.
This is the crash in google play release test with GooglePixel:
10-11 05:34:40.895: D/AndroidRuntime(22146): Shutting down VM
10-11 05:34:40.895: D/AndroidRuntime(22146): --------- beginning of crash
10-11 05:34:40.895: E/AndroidRuntime(22146): FATAL EXCEPTION: main
10-11 05:34:40.895: E/AndroidRuntime(22146): Process: com.google.android.gms.persistent, PID: 22146
10-11 05:34:40.895: E/AndroidRuntime(22146): android.app.RemoteServiceException: can't deliver broadcast
10-11 05:34:40.895: E/AndroidRuntime(22146): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2005)
10-11 05:34:40.895: E/AndroidRuntime(22146): at android.os.Handler.dispatchMessage(Handler.java:106)
10-11 05:34:40.895: E/AndroidRuntime(22146): at android.os.Looper.loop(Looper.java:223)
10-11 05:34:40.895: E/AndroidRuntime(22146): at android.app.ActivityThread.main(ActivityThread.java:7664)
10-11 05:34:40.895: E/AndroidRuntime(22146): at java.lang.reflect.Method.invoke(Native Method)
10-11 05:34:40.895: E/AndroidRuntime(22146): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
10-11 05:34:40.895: E/AndroidRuntime(22146): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Can you help me? Some idea?
I have integrated zxing barcode scanner in my app. When the scanner gets a scan it takes the result and searches an external online database via a async task then opens a new activity based on the results. I am getting a force close that is not consistent, it does not happen every scan, only sometimes so I am having trouble figuring out why I am getting a leaked window error, and only sometimes:
09-25 21:02:48.105 24371-24371/com.beerportfolio.beerportfoliopro E/WindowManager﹕ Activity com.example.beerportfoliopro.BeerPage2 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#424b7198 that was originally added here
android.view.WindowLeaked: Activity com.example.beerportfoliopro.BeerPage2 has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#424b7198 that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:468)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:419)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:351)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:171)
at android.view.Window$LocalWindowManager.addView(Window.java:558)
at android.app.Dialog.show(Dialog.java:282)
at com.example.beerportfoliopro.GetBeerRateJSON.onPreExecute(GetBeerRateJSON.java:52)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
at android.os.AsyncTask.execute(AsyncTask.java:534)
at com.example.beerportfoliopro.GetBeerDataJSON.onPostExecute(GetBeerDataJSON.java:111)
at com.example.beerportfoliopro.GetBeerDataJSON.onPostExecute(GetBeerDataJSON.java:34)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
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:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
09-25 21:02:48.265 24371-24371/com.beerportfolio.beerportfoliopro E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:784)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:476)
at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:182)
at android.app.Dialog.dismissDialog(Dialog.java:328)
at android.app.Dialog.dismiss(Dialog.java:311)
at com.example.beerportfoliopro.GetBeerRateJSON.onPostExecute(GetBeerRateJSON.java:74)
at com.example.beerportfoliopro.GetBeerRateJSON.onPostExecute(GetBeerRateJSON.java:27)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5536)
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:1074)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)
From the stack trace, it looks like your Dialog isn't visible when the AsyncTask finishes its work. In that case, the call to dismiss() will crash the app.
You might try using Dialog.isShowing() to avoid the crash:
protected void onPostExecute(...) {
...
if (dialog.isShowing()) {
dialog.dismiss(); // or .cancel()
}
...
}
I receive this error
10-11 13:58:46.713: E/AndroidRuntime(29407): FATAL EXCEPTION: AsyncTask #2
10-11 13:58:46.713: E/AndroidRuntime(29407): java.lang.RuntimeException: An error occured while executing doInBackground()
10-11 13:58:46.713: E/AndroidRuntime(29407): at android.os.AsyncTask$3.done(AsyncTask.java:299)
10-11 13:58:46.713: E/AndroidRuntime(29407): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
10-11 13:58:46.713: E/AndroidRuntime(29407): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
10-11 13:58:46.713: E/AndroidRuntime(29407): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
10-11 13:58:46.713: E/AndroidRuntime(29407): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
10-11 13:58:46.713: E/AndroidRuntime(29407): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-11 13:58:46.713: E/AndroidRuntime(29407): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-11 13:58:46.713: E/AndroidRuntime(29407): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-11 13:58:46.713: E/AndroidRuntime(29407): at java.lang.Thread.run(Thread.java:856)
10-11 13:58:46.713: E/AndroidRuntime(29407): Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/com.philly.philly/databases/PhillyORM.db
10-11 13:58:46.713: E/AndroidRuntime(29407): at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
10-11 13:58:46.713: E/AndroidRuntime(29407): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1310)
10-11 13:58:46.713: E/AndroidRuntime(29407): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
10-11 13:58:46.713: E/AndroidRuntime(29407): at com.j256.ormlite.android.AndroidCompiledStatement.getCursor(AndroidCompiledStatement.java:154)
10-11 13:58:46.713: E/AndroidRuntime(29407): at com.j256.ormlite.android.AndroidCompiledStatement.runQuery(AndroidCompiledStatement.java:57)
10-11 13:58:46.713: E/AndroidRuntime(29407): at com.j256.ormlite.stmt.SelectIterator.<init>(SelectIterator.java:55)
10-11 13:58:46.713: E/AndroidRuntime(29407): at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java:206)
10-11 13:58:46.713: E/AndroidRuntime(29407): at com.j256.ormlite.stmt.StatementExecutor.query(StatementExecutor.java:155)
10-11 13:58:46.713: E/AndroidRuntime(29407): at com.j256.ormlite.dao.BaseDaoImpl.query(BaseDaoImpl.java:261)
10-11 13:58:46.713: E/AndroidRuntime(29407): at com.j256.ormlite.stmt.QueryBuilder.query(QueryBuilder.java:262)
10-11 13:58:46.713: E/AndroidRuntime(29407): at com.j256.ormlite.stmt.Where.query(Where.java:482)
10-11 13:58:46.713: E/AndroidRuntime(29407): at com.j256.ormlite.dao.BaseDaoImpl.queryForEq(BaseDaoImpl.java:241)
10-11 13:58:46.713: E/AndroidRuntime(29407): at com.philly.philly.Repository.saveOrUpdateKontext(Repository.java:180)
10-11 13:58:46.713: E/AndroidRuntime(29407): at com.philly.philly.PostListActivity$LoadPostsTask.doInBackground(PostListActivity.java:161)
10-11 13:58:46.713: E/AndroidRuntime(29407): at com.philly.philly.PostListActivity$LoadPostsTask.doInBackground(PostListActivity.java:1)
10-11 13:58:46.713: E/AndroidRuntime(29407): at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-11 13:58:46.713: E/AndroidRuntime(29407): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
10-11 13:58:46.713: E/AndroidRuntime(29407): ... 5 more
I believe the key part being 10-11 13:58:46.713: E/AndroidRuntime(29407): Caused by: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/com.philly.philly/databases/PhillyORM.db
This occurs when I rotate my screen while an async task is retrieving data from the remote server.
What I am assuming is happening is that the request is coming back and attempting to write to the database but the activity which started the task has been destroyed and restarted.
If you need to see my code I will add it but I thought the source of this problem might actually be pretty clear just from the error messages and my description.
I'm just looking for how to properly handle screen rotations when retrieving remote data and writing to a local database using ORMLite. Maybe I should be using a service instead of async task?
Thanks in advance.
Your activity is probably closing the DB on rotation.
My suggestion is to use an AsyncTaskLoader and it will take care of the rotation by itself. http://developer.android.com/guide/components/loaders.html
Also a tip I've learned from experience is to have a singleton DB object that will only be opened once through the whole life of your application... and when the application dies, the object is closed automatically.
You are better off using a service to take care of database. When you rotate the screen current layout with all components is destroyed and new one is build using new orientation layout (which will have other components). Also you have the option to block the rotation of screen if you don't really use it.
I am getting following exception on android market for my app.
Exception class java.lang.IllegalArgumentException
Source method WindowManagerImpl.findViewLocked()
I am unable to understand why and where this is coming from? I never got this exception on my device. Does anybody have a clue how to solve this? Or see it on my device?
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
at android.view.Window$LocalWindowManager.removeView(Window.java:432)
at android.app.Dialog.dismissDialog(Dialog.java:278)
at android.app.Dialog.access$000(Dialog.java:71)
at android.app.Dialog$1.run(Dialog.java:111)
at android.app.Dialog.dismiss(Dialog.java:268)
at android.app.Dialog.cancel(Dialog.java:951)
at com.bappy.cror.GameActivity$17$1.run(GameActivity.java:719)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
I am a novice at android development. I have to show a PDF from a URL.
This is my current code but I'm not able to show the PDF file:
public class TestActivity extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.setProperty("http.proxyHost","192.168.0.2");
System.setProperty("http.proxyPort","8080");
showPdf();
}
private void showPdf()
{
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
Log.v("....hello....","");
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");
}
}
Logcat:
10-11 14:50:49.586: ERROR/AndroidRuntime(537): FATAL EXCEPTION: main
10-11 14:50:49.586: ERROR/AndroidRuntime(537): android.app.SuperNotCalledException: Activity {com.vidushi.Test/com.vidushi.Test.TestActivity} did not call through to super.onCreate()
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2629)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.os.Looper.loop(Looper.java:123)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at java.lang.reflect.Method.invokeNative(Native Method)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at java.lang.reflect.Method.invoke(Method.java:521)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-11 14:50:49.586: ERROR/AndroidRuntime(537): at dalvik.system.NativeStart.main(Native Method)
Its working fine here. Still let me suggest you to test whether you have added INTERNET permission in AndroidManifest.xml file or not:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Update:
The link you want to open is: http://litofinter.es.milfoil.arvixe.com/PDF/Book6.pdf
Now its also working fine here: