I am displaying Image in Android App from Hosted Server. So, I need to set StrictMode Policy.
But as I have checked, It requires Api 9 and I want to make it supportable in Api 8 also. So how can I solve this issue ? I am already using this in AsyncTask.
My Code :
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
If I am not using StrictMode then getting Error.
Logcat :
05-08 12:25:08.711: E/AndroidRuntime(27622): android.os.NetworkOnMainThreadException
05-08 12:25:08.711: E/AndroidRuntime(27622): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1208)
05-08 12:25:08.711: E/AndroidRuntime(27622): at java.net.InetAddress.lookupHostByName(InetAddress.java:388)
05-08 12:25:08.711: E/AndroidRuntime(27622): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:239)
05-08 12:25:08.711: E/AndroidRuntime(27622): at java.net.InetAddress.getAllByName(InetAddress.java:214)
05-08 12:25:08.711: E/AndroidRuntime(27622): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
05-08 12:25:08.711: E/AndroidRuntime(27622): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
05-08 12:25:08.711: E/AndroidRuntime(27622): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
05-08 12:25:08.711: E/AndroidRuntime(27622): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
05-08 12:25:08.711: E/AndroidRuntime(27622): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
05-08 12:25:08.711: E/AndroidRuntime(27622): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
05-08 12:25:08.711: E/AndroidRuntime(27622): at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
05-08 12:25:08.711: E/AndroidRuntime(27622): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
05-08 12:25:08.711: E/AndroidRuntime(27622): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
05-08 12:25:08.711: E/AndroidRuntime(27622): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
05-08 12:25:08.711: E/AndroidRuntime(27622): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
05-08 12:25:08.711: E/AndroidRuntime(27622): at com.mytestbuddy.careermirror.Profile$UserProfile.onPostExecute(Profile.java:193)
05-08 12:25:08.711: E/AndroidRuntime(27622): at com.mytestbuddy.careermirror.Profile$UserProfile.onPostExecute(Profile.java:1)
05-08 12:25:08.711: E/AndroidRuntime(27622): at android.os.AsyncTask.finish(AsyncTask.java:631)
05-08 12:25:08.711: E/AndroidRuntime(27622): at android.os.AsyncTask.access$600(AsyncTask.java:177)
05-08 12:25:08.711: E/AndroidRuntime(27622): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
05-08 12:25:08.711: E/AndroidRuntime(27622): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 12:25:08.711: E/AndroidRuntime(27622): at android.os.Looper.loop(Looper.java:155)
05-08 12:25:08.711: E/AndroidRuntime(27622): at android.app.ActivityThread.main(ActivityThread.java:5511)
05-08 12:25:08.711: E/AndroidRuntime(27622): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 12:25:08.711: E/AndroidRuntime(27622): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 12:25:08.711: E/AndroidRuntime(27622): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
05-08 12:25:08.711: E/AndroidRuntime(27622): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
05-08 12:25:08.711: E/AndroidRuntime(27622): at dalvik.system.NativeStart.main(Native Method)
To solve the NetworkOnMainThreadException you're seeing, read the HTTP response input stream in your doInBackground() and not in onPostExecute().
StrictMode is available from 2.3 only, So you can't use it in 2.2.
There is tow possible ways I can give you.
Go with 2.3 [or]
Use AsyncTask in android.
I go with AsyncTsk
I hope this will help you.
Related
I download the example from here. I imported the project in eclipse, added support library v4 to build path. When I run the app, it always crashes. This is the error in LogCat: Could anyone please help me? Thanks.
05-08 22:39:41.396: E/dalvikvm(22444): Could not find class 'com.example.android.scheduler.SampleAlarmReceiver', referenced from method com.example.android.scheduler.MainActivity.<init>
05-08 22:39:41.406: E/AndroidRuntime(22444): FATAL EXCEPTION: main
05-08 22:39:41.406: E/AndroidRuntime(22444): java.lang.NoClassDefFoundError: com.example.android.scheduler.SampleAlarmReceiver
05-08 22:39:41.406: E/AndroidRuntime(22444): at com.example.android.scheduler.MainActivity.<init>(MainActivity.java:34)
05-08 22:39:41.406: E/AndroidRuntime(22444): at java.lang.Class.newInstanceImpl(Native Method)
05-08 22:39:41.406: E/AndroidRuntime(22444): at java.lang.Class.newInstance(Class.java:1319)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2521)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.app.ActivityThread.access$600(ActivityThread.java:162)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1370)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.os.Looper.loop(Looper.java:158)
05-08 22:39:41.406: E/AndroidRuntime(22444): at android.app.ActivityThread.main(ActivityThread.java:5777)
05-08 22:39:41.406: E/AndroidRuntime(22444): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 22:39:41.406: E/AndroidRuntime(22444): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 22:39:41.406: E/AndroidRuntime(22444): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
05-08 22:39:41.406: E/AndroidRuntime(22444): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
05-08 22:39:41.406: E/AndroidRuntime(22444): at dalvik.system.NativeStart.main(Native Method)
I got the same issue when I added support v4 lib via "add external jar" in build path.
To solve it:
remove the support v4 lib from build path
create a directory named "libs" in the root on the project
copy the lib into the newly created directory.
Eclipse should now show a new "library directory" in your project called "Android Private Libraries" which include support library v4
Refresh, clean ... and it should work.
My app crashes and gives me the following trace:
05-08 08:49:15.228: E/AndroidRuntime(1022): FATAL EXCEPTION: main
05-08 08:49:15.228: E/AndroidRuntime(1022): java.lang.IllegalStateException: Activity has been destroyed
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1365)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:578)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:161)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.automation.standards.VerticalViewPager.populate(VerticalViewPager.java:965)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.automation.standards.VerticalViewPager.populate(VerticalViewPager.java:811)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.automation.standards.VerticalViewPager.setAdapter(VerticalViewPager.java:334)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.automation.isolace.Lighting.assign_vertical_gangs_swipping(Lighting.java:505)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.automation.isolace.Lighting.select_room(Lighting.java:403)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.automation.isolace.Lighting$11.onClick(Lighting.java:351)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.view.View.performClick(View.java:4084)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.view.View$PerformClick.run(View.java:16966)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.os.Handler.handleCallback(Handler.java:615)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.os.Looper.loop(Looper.java:137)
05-08 08:49:15.228: E/AndroidRuntime(1022): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-08 08:49:15.228: E/AndroidRuntime(1022): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 08:49:15.228: E/AndroidRuntime(1022): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-08 08:49:15.228: E/AndroidRuntime(1022): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-08 08:49:15.228: E/AndroidRuntime(1022): at dalvik.system.NativeStart.main(Native Method)
The point is I can't deal with that Activity Destroy thing as the Activity is Destroyed without calling onDestroy() method and I figured that because I override the onDestroy method but it didn't go through it, also I checked the isDestroyed() output but the strange thing it even not giving me true despite I put the Line that makes the Activity crashes in a try-ctach block, and prints isDestroyed in the catch block (which can mean that that line itself is the one which makes the Activity crashes) and here's the code area that the app crashes in:
List<Fragment> temp_fragments = fragments; // list of fragments to add to a VerticalViewPager and return it through pageAdapter
TabAdapter2 = new LightVerticalPageAdapter(super.getSupportFragmentManager(), temp_fragments);
Tab2 = (VerticalViewPager) SomeFragment.views.findViewById(R.id.vertical_pager);// "SomeFragment" is the fragment that contains the VerticalPager and the "views" var is the var that stores Fragmrnt view when hitting fragment onViewCreated at the first time
Tab2.setAdapter(TabAdapter2); // HERE IS WHERE THE APP CRASHES AND NOT CALLS ACTIVITY onDestroy()
So this app I am working on, works just fine on a really old miserable Android 2.3.3 phone. However when running it on the GS4, the GS4 is throwing out of memory exceptions every time is has to load a resource from the drawables, that is predefined in the xml.
<ImageView
android:id="#+id/ivLearnMore"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/learn_more" />
For example this Imageview will throw an exception when inflating the layout because it already has an image assigned. (256x256)
what is going on?
05-08 10:33:54.972: E/dalvikvm-heap(24423): Out of memory on a 16777232-byte allocation.
05-08 10:33:54.972: I/dalvikvm(24423): "main" prio=5 tid=1 RUNNABLE
05-08 10:33:54.972: I/dalvikvm(24423): | group="main" sCount=0 dsCount=0 obj=0x41187b38 self=0x40dd1b68
05-08 10:33:54.972: I/dalvikvm(24423): | sysTid=24423 nice=0 sched=0/0 cgrp=apps handle=1074533852
05-08 10:33:54.972: I/dalvikvm(24423): | state=R schedstat=( 0 0 0 ) utm=147 stm=1265 core=0
05-08 10:33:54.972: I/dalvikvm(24423): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-08 10:33:54.972: I/dalvikvm(24423): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
05-08 10:33:54.972: I/dalvikvm(24423): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
05-08 10:33:54.972: I/dalvikvm(24423): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:817)
05-08 10:33:54.972: I/dalvikvm(24423): at android.content.res.Resources.loadDrawable(Resources.java:2854)
05-08 10:33:54.972: I/dalvikvm(24423): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
05-08 10:33:54.972: I/dalvikvm(24423): at android.view.View.<init>(View.java:3460)
05-08 10:33:54.972: I/dalvikvm(24423): at android.view.ViewGroup.<init>(ViewGroup.java:446)
05-08 10:33:54.972: I/dalvikvm(24423): at android.widget.LinearLayout.<init>(LinearLayout.java:176)
05-08 10:33:54.972: I/dalvikvm(24423): at android.widget.LinearLayout.<init>(LinearLayout.java:172)
05-08 10:33:54.972: I/dalvikvm(24423): at java.lang.reflect.Constructor.constructNative(Native Method)
05-08 10:33:54.972: I/dalvikvm(24423): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-08 10:33:54.972: I/dalvikvm(24423): at android.view.LayoutInflater.createView(LayoutInflater.java:593)
05-08 10:33:54.972: I/dalvikvm(24423): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-08 10:33:54.972: I/dalvikvm(24423): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
05-08 10:33:54.972: I/dalvikvm(24423): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
05-08 10:33:54.972: I/dalvikvm(24423): at android.view.LayoutInflater.inflate(LayoutInflater.java:467)
05-08 10:33:54.972: I/dalvikvm(24423): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-08 10:33:54.972: I/dalvikvm(24423): at com.travelstorysgps.travelstorys.FragmentInfo.onCreateView(FragmentInfo.java:54)
05-08 10:33:54.972: I/dalvikvm(24423): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
05-08 10:33:54.972: I/dalvikvm(24423): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
05-08 10:33:54.972: I/dalvikvm(24423): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
05-08 10:33:54.972: I/dalvikvm(24423): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
05-08 10:33:54.972: I/dalvikvm(24423): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
05-08 10:33:54.972: I/dalvikvm(24423): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
05-08 10:33:54.972: I/dalvikvm(24423): at android.os.Handler.handleCallback(Handler.java:725)
05-08 10:33:54.972: I/dalvikvm(24423): at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 10:33:54.972: I/dalvikvm(24423): at android.os.Looper.loop(Looper.java:137)
05-08 10:33:54.972: I/dalvikvm(24423): at android.app.ActivityThread.main(ActivityThread.java:5293)
05-08 10:33:54.972: I/dalvikvm(24423): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 10:33:54.972: I/dalvikvm(24423): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 10:33:54.972: I/dalvikvm(24423): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-08 10:33:54.972: I/dalvikvm(24423): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-08 10:33:54.972: I/dalvikvm(24423): at dalvik.system.NativeStart.main(Native Method)
05-08 10:33:54.972: D/skia(24423): --- decoder->decode returned false
05-08 10:33:54.972: D/AndroidRuntime(24423): Shutting down VM
05-08 10:33:54.972: W/dalvikvm(24423): threadid=1: thread exiting with uncaught exception (group=0x41186ac8)
05-08 10:33:54.992: E/AndroidRuntime(24423): FATAL EXCEPTION: main
05-08 10:33:54.992: E/AndroidRuntime(24423): android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.view.LayoutInflater.createView(LayoutInflater.java:619)
05-08 10:33:54.992: E/AndroidRuntime(24423): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.view.LayoutInflater.inflate(LayoutInflater.java:467)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-08 10:33:54.992: E/AndroidRuntime(24423): at com.travelstorysgps.travelstorys.FragmentInfo.onCreateView(FragmentInfo.java:54)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.os.Handler.handleCallback(Handler.java:725)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.os.Looper.loop(Looper.java:137)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.app.ActivityThread.main(ActivityThread.java:5293)
05-08 10:33:54.992: E/AndroidRuntime(24423): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 10:33:54.992: E/AndroidRuntime(24423): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 10:33:54.992: E/AndroidRuntime(24423): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-08 10:33:54.992: E/AndroidRuntime(24423): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-08 10:33:54.992: E/AndroidRuntime(24423): at dalvik.system.NativeStart.main(Native Method)
05-08 10:33:54.992: E/AndroidRuntime(24423): Caused by: java.lang.reflect.InvocationTargetException
05-08 10:33:54.992: E/AndroidRuntime(24423): at java.lang.reflect.Constructor.constructNative(Native Method)
05-08 10:33:54.992: E/AndroidRuntime(24423): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.view.LayoutInflater.createView(LayoutInflater.java:593)
05-08 10:33:54.992: E/AndroidRuntime(24423): ... 21 more
05-08 10:33:54.992: E/AndroidRuntime(24423): Caused by: java.lang.OutOfMemoryError
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:817)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.content.res.Resources.loadDrawable(Resources.java:2854)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.view.View.<init>(View.java:3460)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.view.ViewGroup.<init>(ViewGroup.java:446)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.widget.LinearLayout.<init>(LinearLayout.java:176)
05-08 10:33:54.992: E/AndroidRuntime(24423): at android.widget.LinearLayout.<init>(LinearLayout.java:172)
05-08 10:33:54.992: E/AndroidRuntime(24423): ... 24 more
Here is a exception from a different screen
05-08 10:35:29.565: E/dalvikvm-heap(24774): Out of memory on a 16777232-byte allocation.
05-08 10:35:29.565: I/dalvikvm(24774): "main" prio=5 tid=1 RUNNABLE
05-08 10:35:29.565: I/dalvikvm(24774): | group="main" sCount=0 dsCount=0 obj=0x41187b38 self=0x40dd1b68
05-08 10:35:29.565: I/dalvikvm(24774): | sysTid=24774 nice=0 sched=0/0 cgrp=apps handle=1074533852
05-08 10:35:29.565: I/dalvikvm(24774): | state=R schedstat=( 0 0 0 ) utm=175 stm=2086 core=1
05-08 10:35:29.565: I/dalvikvm(24774): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-08 10:35:29.565: I/dalvikvm(24774): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
05-08 10:35:29.565: I/dalvikvm(24774): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
05-08 10:35:29.565: I/dalvikvm(24774): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:817)
05-08 10:35:29.565: I/dalvikvm(24774): at android.content.res.Resources.loadDrawable(Resources.java:2854)
05-08 10:35:29.565: I/dalvikvm(24774): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
05-08 10:35:29.565: I/dalvikvm(24774): at android.view.View.<init>(View.java:3460)
05-08 10:35:29.565: I/dalvikvm(24774): at android.view.ViewGroup.<init>(ViewGroup.java:446)
05-08 10:35:29.565: I/dalvikvm(24774): at android.widget.LinearLayout.<init>(LinearLayout.java:176)
05-08 10:35:29.565: I/dalvikvm(24774): at android.widget.LinearLayout.<init>(LinearLayout.java:172)
05-08 10:35:29.565: I/dalvikvm(24774): at java.lang.reflect.Constructor.constructNative(Native Method)
05-08 10:35:29.565: I/dalvikvm(24774): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-08 10:35:29.565: I/dalvikvm(24774): at android.view.LayoutInflater.createView(LayoutInflater.java:593)
05-08 10:35:29.565: I/dalvikvm(24774): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-08 10:35:29.565: I/dalvikvm(24774): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
05-08 10:35:29.565: I/dalvikvm(24774): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
05-08 10:35:29.565: I/dalvikvm(24774): at android.view.LayoutInflater.inflate(LayoutInflater.java:467)
05-08 10:35:29.565: I/dalvikvm(24774): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-08 10:35:29.565: I/dalvikvm(24774): at com.travelstorysgps.travelstorys.FragmentDonate.onCreateView(FragmentDonate.java:53)
05-08 10:35:29.565: I/dalvikvm(24774): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
05-08 10:35:29.565: I/dalvikvm(24774): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
05-08 10:35:29.565: I/dalvikvm(24774): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
05-08 10:35:29.565: I/dalvikvm(24774): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
05-08 10:35:29.565: I/dalvikvm(24774): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
05-08 10:35:29.565: I/dalvikvm(24774): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
05-08 10:35:29.565: I/dalvikvm(24774): at android.os.Handler.handleCallback(Handler.java:725)
05-08 10:35:29.565: I/dalvikvm(24774): at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 10:35:29.565: I/dalvikvm(24774): at android.os.Looper.loop(Looper.java:137)
05-08 10:35:29.565: I/dalvikvm(24774): at android.app.ActivityThread.main(ActivityThread.java:5293)
05-08 10:35:29.565: I/dalvikvm(24774): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 10:35:29.565: I/dalvikvm(24774): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 10:35:29.565: I/dalvikvm(24774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-08 10:35:29.565: I/dalvikvm(24774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-08 10:35:29.565: I/dalvikvm(24774): at dalvik.system.NativeStart.main(Native Method)
05-08 10:35:29.565: D/AbsListView(24774): [unregisterDoubleTapMotionListener]
05-08 10:35:29.565: I/MotionRecognitionManager(24774): .unregisterListener : / listener count = 0->0,
05-08 10:35:29.565: D/skia(24774): --- decoder->decode returned false
05-08 10:35:29.565: D/AbsListView(24774): unregisterIRListener() is called
05-08 10:35:29.565: D/AndroidRuntime(24774): Shutting down VM
05-08 10:35:29.565: W/dalvikvm(24774): threadid=1: thread exiting with uncaught exception (group=0x41186ac8)
05-08 10:35:29.595: E/AndroidRuntime(24774): FATAL EXCEPTION: main
05-08 10:35:29.595: E/AndroidRuntime(24774): android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.view.LayoutInflater.createView(LayoutInflater.java:619)
05-08 10:35:29.595: E/AndroidRuntime(24774): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.view.LayoutInflater.inflate(LayoutInflater.java:467)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-08 10:35:29.595: E/AndroidRuntime(24774): at com.travelstorysgps.travelstorys.FragmentDonate.onCreateView(FragmentDonate.java:53)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.os.Handler.handleCallback(Handler.java:725)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.os.Looper.loop(Looper.java:137)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.app.ActivityThread.main(ActivityThread.java:5293)
05-08 10:35:29.595: E/AndroidRuntime(24774): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 10:35:29.595: E/AndroidRuntime(24774): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 10:35:29.595: E/AndroidRuntime(24774): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-08 10:35:29.595: E/AndroidRuntime(24774): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-08 10:35:29.595: E/AndroidRuntime(24774): at dalvik.system.NativeStart.main(Native Method)
05-08 10:35:29.595: E/AndroidRuntime(24774): Caused by: java.lang.reflect.InvocationTargetException
05-08 10:35:29.595: E/AndroidRuntime(24774): at java.lang.reflect.Constructor.constructNative(Native Method)
05-08 10:35:29.595: E/AndroidRuntime(24774): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.view.LayoutInflater.createView(LayoutInflater.java:593)
05-08 10:35:29.595: E/AndroidRuntime(24774): ... 21 more
05-08 10:35:29.595: E/AndroidRuntime(24774): Caused by: java.lang.OutOfMemoryError
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:817)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.content.res.Resources.loadDrawable(Resources.java:2854)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.view.View.<init>(View.java:3460)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.view.ViewGroup.<init>(ViewGroup.java:446)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.widget.LinearLayout.<init>(LinearLayout.java:176)
05-08 10:35:29.595: E/AndroidRuntime(24774): at android.widget.LinearLayout.<init>(LinearLayout.java:172)
05-08 10:35:29.595: E/AndroidRuntime(24774): ... 24 more
and here is a 3rd and different screen
05-08 10:37:20.113: E/dalvikvm-heap(25740): Out of memory on a 16777232-byte allocation.
05-08 10:37:20.123: I/dalvikvm(25740): "main" prio=5 tid=1 RUNNABLE
05-08 10:37:20.123: I/dalvikvm(25740): | group="main" sCount=0 dsCount=0 obj=0x41187b38 self=0x40dd1b68
05-08 10:37:20.123: I/dalvikvm(25740): | sysTid=25740 nice=0 sched=0/0 cgrp=apps handle=1074533852
05-08 10:37:20.123: I/dalvikvm(25740): | state=R schedstat=( 0 0 0 ) utm=156 stm=1070 core=1
05-08 10:37:20.123: I/dalvikvm(25740): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-08 10:37:20.123: I/dalvikvm(25740): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
05-08 10:37:20.123: I/dalvikvm(25740): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
05-08 10:37:20.123: I/dalvikvm(25740): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:817)
05-08 10:37:20.123: I/dalvikvm(25740): at android.content.res.Resources.loadDrawable(Resources.java:2854)
05-08 10:37:20.123: I/dalvikvm(25740): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
05-08 10:37:20.123: I/dalvikvm(25740): at android.view.View.<init>(View.java:3460)
05-08 10:37:20.123: I/dalvikvm(25740): at android.view.ViewGroup.<init>(ViewGroup.java:446)
05-08 10:37:20.123: I/dalvikvm(25740): at android.widget.LinearLayout.<init>(LinearLayout.java:176)
05-08 10:37:20.123: I/dalvikvm(25740): at android.widget.LinearLayout.<init>(LinearLayout.java:172)
05-08 10:37:20.123: I/dalvikvm(25740): at java.lang.reflect.Constructor.constructNative(Native Method)
05-08 10:37:20.123: I/dalvikvm(25740): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-08 10:37:20.123: I/dalvikvm(25740): at android.view.LayoutInflater.createView(LayoutInflater.java:593)
05-08 10:37:20.123: I/dalvikvm(25740): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-08 10:37:20.123: I/dalvikvm(25740): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
05-08 10:37:20.123: I/dalvikvm(25740): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
05-08 10:37:20.123: I/dalvikvm(25740): at android.view.LayoutInflater.inflate(LayoutInflater.java:467)
05-08 10:37:20.123: I/dalvikvm(25740): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-08 10:37:20.123: I/dalvikvm(25740): at com.travelstorysgps.travelstorys.FragmentConnect.onCreateView(FragmentConnect.java:73)
05-08 10:37:20.123: I/dalvikvm(25740): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
05-08 10:37:20.123: I/dalvikvm(25740): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
05-08 10:37:20.123: I/dalvikvm(25740): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
05-08 10:37:20.123: I/dalvikvm(25740): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
05-08 10:37:20.123: I/dalvikvm(25740): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
05-08 10:37:20.123: I/dalvikvm(25740): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
05-08 10:37:20.123: I/dalvikvm(25740): at android.os.Handler.handleCallback(Handler.java:725)
05-08 10:37:20.123: I/dalvikvm(25740): at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 10:37:20.123: I/dalvikvm(25740): at android.os.Looper.loop(Looper.java:137)
05-08 10:37:20.123: I/dalvikvm(25740): at android.app.ActivityThread.main(ActivityThread.java:5293)
05-08 10:37:20.123: I/dalvikvm(25740): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 10:37:20.123: I/dalvikvm(25740): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 10:37:20.123: I/dalvikvm(25740): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-08 10:37:20.123: I/dalvikvm(25740): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-08 10:37:20.123: I/dalvikvm(25740): at dalvik.system.NativeStart.main(Native Method)
05-08 10:37:20.123: D/skia(25740): --- decoder->decode returned false
05-08 10:37:20.123: D/AndroidRuntime(25740): Shutting down VM
05-08 10:37:20.123: W/dalvikvm(25740): threadid=1: thread exiting with uncaught exception (group=0x41186ac8)
05-08 10:37:20.133: E/AndroidRuntime(25740): FATAL EXCEPTION: main
05-08 10:37:20.133: E/AndroidRuntime(25740): android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.view.LayoutInflater.createView(LayoutInflater.java:619)
05-08 10:37:20.133: E/AndroidRuntime(25740): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.view.LayoutInflater.inflate(LayoutInflater.java:467)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-08 10:37:20.133: E/AndroidRuntime(25740): at com.travelstorysgps.travelstorys.FragmentConnect.onCreateView(FragmentConnect.java:73)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.os.Handler.handleCallback(Handler.java:725)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.os.Looper.loop(Looper.java:137)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.app.ActivityThread.main(ActivityThread.java:5293)
05-08 10:37:20.133: E/AndroidRuntime(25740): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 10:37:20.133: E/AndroidRuntime(25740): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 10:37:20.133: E/AndroidRuntime(25740): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-08 10:37:20.133: E/AndroidRuntime(25740): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-08 10:37:20.133: E/AndroidRuntime(25740): at dalvik.system.NativeStart.main(Native Method)
05-08 10:37:20.133: E/AndroidRuntime(25740): Caused by: java.lang.reflect.InvocationTargetException
05-08 10:37:20.133: E/AndroidRuntime(25740): at java.lang.reflect.Constructor.constructNative(Native Method)
05-08 10:37:20.133: E/AndroidRuntime(25740): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.view.LayoutInflater.createView(LayoutInflater.java:593)
05-08 10:37:20.133: E/AndroidRuntime(25740): ... 21 more
05-08 10:37:20.133: E/AndroidRuntime(25740): Caused by: java.lang.OutOfMemoryError
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:817)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.content.res.Resources.loadDrawable(Resources.java:2854)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.view.View.<init>(View.java:3460)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.view.ViewGroup.<init>(ViewGroup.java:446)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.widget.LinearLayout.<init>(LinearLayout.java:176)
05-08 10:37:20.133: E/AndroidRuntime(25740): at android.widget.LinearLayout.<init>(LinearLayout.java:172)
05-08 10:37:20.133: E/AndroidRuntime(25740): ... 24 more
(#Arash's answer provides a workaround, but this is my attempt to explain why it may work.)
So you have a rather big image in the drawable resource directory, you reference it in your layout xml file, and get an out of memory error at runtime when inflating it.
When loading drawable resources, Android will perform some pre-scaling if it deems it necessary. From the official documentation:
Based on the density of the current screen, the system uses any size- or density-specific resources from your application and displays them without scaling. If resources are not available in the correct density, the system loads the default resources and scales them up or down as needed to match the current screen's density. The system assumes that default resources (those from a directory without configuration qualifiers) are designed for the baseline screen density (mdpi), unless they are loaded from a density-specific resource directory.
This means 2 things:
If there's no resource of the density of the environment the application is currently running on, the system will take a resource of another density and scale it (up or down) to match the target density
Resources put in the drawable directory are assumed to be targeting an mdpi density
So you're currently running on an xxhdpi phone. The system wants to load the learn_more drawable resource to paint it on the ivLearnMore widget. It will look for it in the drawable-xxhdpi in priority but won't find it there, so will take the closest one it finds, in this case the one in the drawable directory (which it assumes to be targeting mdpi density), and load it into memory scaling it by a factor of 3 which is a lot if your image file was significantly big and can easily require more memory than is available to the application (and cause an out of memory error).
This is also why it loaded fine on your old crappy 2.3 device: the device was most likely of mdpi or hdpi density and the system didn't try to upscale it or did it by a factor of only 1.5.
The main thing here being that you put a resource suitable for an xxhdpi (or more ?) density in an mdpi directory.
So you have several options:
provide one resource appropriately sized per density (i.e. one in each drawable-* directory): this is the best to avoid any problem, when possible
if you only have one version of the resource, put it in the directory matching its density (drawable being equivalent to drawable-mdpi!), in your case maybe drawable-xxhdpi (depends on your resource)
put the resource in the drawable-nodpi directory, this will prevent the system from performing any pre-scaling of the resource (but this is typically for density-agnostic resources e.g. which you resize yourself at runtime)
I had the same problem and that was : Galaxy S4 and all 1920*1080 resolution devices , check in xxhdpi folder first and if there is not specific images,it will scale other sizes like xhdpi,... so i moved my pictures to xxhdpi folder and it Solved!
I have discovered the problem. Background images are apparently not handled very efficiently, especially not for a 1920x1080 screen. Therefor you should use a custom xml drawable, a flat color, or a 24-bit jpg. Funny enough I just ran some tests and a 1920x1080 jpeg takes up 95.60 KB while the same image rendered as a png takes up 929.09 KB.
So I did some testing and found that xml defined drawables with gradients etc. are super fast, I then tried my 1920x1080 jpg and it was super fast, so then I put in a 1920x1080 png and got the error. This is funny to me because the png I has set at the start for HD screens was only 910x540 and I would get the error.
So lesson here is if you want a image background use a jpg.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
05-08 11:04:12.336: E/AndroidRuntime(678): FATAL EXCEPTION: main
05-08 11:04:12.336: E/AndroidRuntime(678): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android/com.android.Calendar_googleActivity}: android.os.NetworkOnMainThreadException
05-08 11:04:12.336: E/AndroidRuntime(678): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-08 11:04:12.336: E/AndroidRuntime(678): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-08 11:04:12.336: E/AndroidRuntime(678): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-08 11:04:12.336: E/AndroidRuntime(678): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-08 11:04:12.336: E/AndroidRuntime(678): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 11:04:12.336: E/AndroidRuntime(678): at android.os.Looper.loop(Looper.java:137)
05-08 11:04:12.336: E/AndroidRuntime(678): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-08 11:04:12.336: E/AndroidRuntime(678): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 11:04:12.336: E/AndroidRuntime(678): at java.lang.reflect.Method.invoke(Method.java:511)
05-08 11:04:12.336: E/AndroidRuntime(678): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-08 11:04:12.336: E/AndroidRuntime(678): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-08 11:04:12.336: E/AndroidRuntime(678): at dalvik.system.NativeStart.main(Native Method)
05-08 11:04:12.336: E/AndroidRuntime(678): Caused by: android.os.NetworkOnMainThreadException
05-08 11:04:12.336: E/AndroidRuntime(678): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
05-08 11:04:12.336: E/AndroidRuntime(678): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
05-08 11:04:12.336: E/AndroidRuntime(678): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
05-08 11:04:12.336: E/AndroidRuntime(678): at java.net.InetAddress.getAllByName(InetAddress.java:220)
05-08 11:04:12.336: E/AndroidRuntime(678): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
05-08 11:04:12.336: E/AndroidRuntime(678): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
05-08 11:04:12.336: E/AndroidRuntime(678): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
05-08 11:04:12.336: E/AndroidRuntime(678): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
05-08 11:04:12.336: E/AndroidRuntime(678): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
05-08 11:04:12.336: E/AndroidRuntime(678): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
05-08 11:04:12.336: E/AndroidRuntime(678): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:460)
05-08 11:04:12.336: E/AndroidRuntime(678): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:432)
05-08 11:04:12.336: E/AndroidRuntime(678): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
05-08 11:04:12.336: E/AndroidRuntime(678): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
05-08 11:04:12.336: E/AndroidRuntime(678): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
05-08 11:04:12.336: E/AndroidRuntime(678): at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:164)
05-08 11:04:12.336: E/AndroidRuntime(678): at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:88)
05-08 11:04:12.336: E/AndroidRuntime(678): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:814)
05-08 11:04:12.336: E/AndroidRuntime(678): at com.google.api.client.googleapis.json.GoogleJsonResponseException.execute(GoogleJsonResponseException.java:182)
05-08 11:04:12.336: E/AndroidRuntime(678): at com.google.api.client.googleapis.services.GoogleClient.executeUnparsed(GoogleClient.java:115)
05-08 11:04:12.336: E/AndroidRuntime(678): at com.google.api.client.http.json.JsonHttpRequest.executeUnparsed(JsonHttpRequest.java:112)
05-08 11:04:12.336: E/AndroidRuntime(678): at com.google.api.services.calendar.Calendar$CalendarList$List.execute(Calendar.java:510)
05-08 11:04:12.336: E/AndroidRuntime(678): at com.android.Calendar_googleActivity.onAuthToken(Calendar_googleActivity.java:267)
05-08 11:04:12.336: E/AndroidRuntime(678): at com.android.Calendar_googleActivity.gotAccount(Calendar_googleActivity.java:118)
05-08 11:04:12.336: E/AndroidRuntime(678): at com.android.Calendar_googleActivity.onCreate(Calendar_googleActivity.java:108)
05-08 11:04:12.336: E/AndroidRuntime(678): at android.app.Activity.performCreate(Activity.java:4465)
05-08 11:04:12.336: E/AndroidRuntime(678): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-08 11:04:12.336: E/AndroidRuntime(678): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-08 11:04:12.336: E/AndroidRuntime(678): ... 11 more
Caused by: android.os.NetworkOnMainThreadException
You've always been warned against doing networking on the UI thread as that could lead to UI lag and application not responding errors if the network operation is delayed.
In recent releases you are now actually prohibited - by the proactive error above - from attempting to 'get away with it'
So get your network usage off of the UI thread and you should be all set. We do not need to discuss how to do that here - it's well covered in the documentation and previous questions.
I have a application which use two layouts in portrait ans landscape. To load content form web at the initial load I use a AsyncTask and a progress bar.
I checked this. Since I have two layouts this is not the solution.
The exception is given below.
> 05-08 16:44:43.483: E/WindowManager(20138): Activity com.news.one has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#482b0130 that was originally added here
05-08 16:44:43.483: E/WindowManager(20138): android.view.WindowLeaked: Activity com.news.one has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView#482b0130 that was originally added here
05-08 16:44:43.483: E/WindowManager(20138): at android.view.ViewRoot.<init>(ViewRoot.java:247)
05-08 16:44:43.483: E/WindowManager(20138): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:181)
05-08 16:44:43.483: E/WindowManager(20138): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:124)
05-08 16:44:43.483: E/WindowManager(20138): at android.view.Window$LocalWindowManager.addView(Window.java:424)
05-08 16:44:43.483: E/WindowManager(20138): at android.app.Dialog.show(Dialog.java:241)
05-08 16:44:43.483: E/WindowManager(20138): at com.news.one$DownloadNews.onPreExecute(AdaDeranaTabActivity.java:365)
05-08 16:44:43.483: E/WindowManager(20138): at android.os.AsyncTask.execute(AsyncTask.java:391)
05-08 16:44:43.483: E/WindowManager(20138): at com.news.one.onCreate(AdaDeranaTabActivity.java:201)
05-08 16:44:43.483: E/WindowManager(20138): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-08 16:44:43.483: E/WindowManager(20138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-08 16:44:43.483: E/WindowManager(20138): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-08 16:44:43.483: E/WindowManager(20138): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-08 16:44:43.483: E/WindowManager(20138): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-08 16:44:43.483: E/WindowManager(20138): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 16:44:43.483: E/WindowManager(20138): at android.os.Looper.loop(Looper.java:123)
05-08 16:44:43.483: E/WindowManager(20138): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-08 16:44:43.483: E/WindowManager(20138): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 16:44:43.483: E/WindowManager(20138): at java.lang.reflect.Method.invoke(Method.java:521)
05-08 16:44:43.483: E/WindowManager(20138): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-08 16:44:43.483: E/WindowManager(20138): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-08 16:44:43.483: E/WindowManager(20138): at dalvik.system.NativeStart.main(Native Method)
05-08 16:44:54.065: E/AndroidRuntime(20138): FATAL EXCEPTION: main
05-08 16:44:54.065: E/AndroidRuntime(20138): java.lang.IllegalArgumentException: View not attached to window manager
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:388)
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:233)
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.view.Window$LocalWindowManager.removeView(Window.java:432)
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.app.Dialog.dismissDialog(Dialog.java:278)
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.app.Dialog.access$000(Dialog.java:71)
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.app.Dialog$1.run(Dialog.java:111)
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.app.Dialog.dismiss(Dialog.java:268)
05-08 16:44:54.065: E/AndroidRuntime(20138): at com.news.one$DownloadNews.onPostExecute(AdaDeranaTabActivity.java:376)
05-08 16:44:54.065: E/AndroidRuntime(20138): at com.news.one$DownloadNews.onPostExecute(AdaDeranaTabActivity.java:1)
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.os.AsyncTask.finish(AsyncTask.java:417)
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.os.AsyncTask.access$300(AsyncTask.java:127)
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.os.Looper.loop(Looper.java:123)
05-08 16:44:54.065: E/AndroidRuntime(20138): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-08 16:44:54.065: E/AndroidRuntime(20138): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 16:44:54.065: E/AndroidRuntime(20138): at java.lang.reflect.Method.invoke(Method.java:521)
05-08 16:44:54.065: E/AndroidRuntime(20138): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-08 16:44:54.065: E/AndroidRuntime(20138): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-08 16:44:54.065: E/AndroidRuntime(20138): at dalvik.system.NativeStart.main(Native Method)
Is there a method to lock the rotation change till the application loads it self?
Or and other idea?
Thanks in advance.
When you switch orientations, Android will create a new View. You're probably getting crashes because your background thread is trying to change the state on the old one. (It may also be having trouble because your background thread isn't on the UI thread).
These are the solutions:
How to handle screen orientation change when progress dialog and background thread active?
Activity restart on rotation Android
I called the progressDialog.dismiss() in the onDestroy() method.
During a orientation change, the activity restarts. So before restart we have to destroy the current progressDialog. This does the trick. :D
You are getting WindowLeak Exception, this exception occur when any dialog/progressBar uses the reference of context and context reference lost due to orientation change.
So put below code for all activity tag in manifest file.
android:configChanges="orientation|keyboard"
example:
<activity
android:name=".InviteActivity" android:configChanges="orientation|keyboard"/>
and use below code in activity
#Override
public void onConfigurationChanged(Configuration newConfig)
{
setContentView(R.layout.YOUR_LAYOUT);
super.onConfigurationChanged(newConfig);
}
I had the same problem and solved it that way that I locked the orientation before start synchronisation and set it back after synchronize:
// before
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
// after synchronisation:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);