So I have a react-native app and it works fine in my simulat in computer, but when I want to check it in real device I get errors..
1.I run react-native run-android (app installs to real device, with just giving warning about adb reverse, cuz device's android version is
4.4.2)
2.When app opens in real device, says "Unable to load script from assets etc."
3.Then I try to open Dev Settings to connect to bundle via wifi as suggested and My app crashes!.. I tried in 2 different devices it
crashed in both.
I tracked it with android device monitor and I get some errors starting with :
07-18 17:03:24.596: E/AndroidRuntime(1160):
android.view.InflateException: Binary XML file line #19: Error
inflating class android.widget.CheckBox 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.view.LayoutInflater.createView(LayoutInflater.java:626) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.view.LayoutInflater.inflate(LayoutInflater.java:470) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.LayoutInflater.inflate(LayoutInflater.java:398) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.LayoutInflater.inflate(LayoutInflater.java:354) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.preference.Preference.onCreateView(Preference.java:531) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.preference.Preference.getView(Preference.java:494) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.preference.PreferenceGroupAdapter.getView(PreferenceGroupAdapter.java:222)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.widget.AbsListView.obtainView(AbsListView.java:2742) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.widget.ListView.makeAndAddView(ListView.java:1811) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.widget.ListView.fillDown(ListView.java:697) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.widget.ListView.fillFromTop(ListView.java:763) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.widget.ListView.layoutChildren(ListView.java:1641) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.widget.AbsListView.onLayout(AbsListView.java:2567) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.View.layout(View.java:15819) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.view.ViewGroup.layout(ViewGroup.java:4884) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.widget.LinearLayout.onLayout(LinearLayout.java:1440) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.View.layout(View.java:15819) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.view.ViewGroup.layout(ViewGroup.java:4884) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1666)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.widget.LinearLayout.onLayout(LinearLayout.java:1442) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.View.layout(View.java:15819) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.view.ViewGroup.layout(ViewGroup.java:4884) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.widget.LinearLayout.onLayout(LinearLayout.java:1440) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.View.layout(View.java:15819) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.view.ViewGroup.layout(ViewGroup.java:4884) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.widget.FrameLayout.onLayout(FrameLayout.java:388) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.View.layout(View.java:15819) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.view.ViewGroup.layout(ViewGroup.java:4884) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.widget.LinearLayout.onLayout(LinearLayout.java:1440) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.View.layout(View.java:15819) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.view.ViewGroup.layout(ViewGroup.java:4884) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.widget.FrameLayout.onLayout(FrameLayout.java:388) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.View.layout(View.java:15819) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.view.ViewGroup.layout(ViewGroup.java:4884) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2391) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2099)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1270) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6721)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:812)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.view.Choreographer.doCallbacks(Choreographer.java:612) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.Choreographer.doFrame(Choreographer.java:582) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:798)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
android.os.Handler.handleCallback(Handler.java:733) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.os.Handler.dispatchMessage(Handler.java:95) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
android.os.Looper.loop(Looper.java:146) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
android.app.ActivityThread.main(ActivityThread.java:5641) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
java.lang.reflect.Method.invokeNative(Native Method) 07-18
17:03:24.596: E/AndroidRuntime(1160): at
java.lang.reflect.Method.invoke(Method.java:515) 07-18 17:03:24.596:
E/AndroidRuntime(1160): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1288)
07-18 17:03:24.596: E/AndroidRuntime(1160): at
com.android.internal.os.Zygote 07-18 17:03:24.656: A/libc(1215): Fatal
signal 13 (SIGPIPE) at 0x000004bf (code=0), thread 1215 (uptime)
Any ideas how I can solve this..?
app/android/app/build.gradle :
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.gotl"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
compile project(':react-native-track-player')
compile project(':react-native-sound-player')
compile project(':react-native-sound')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile 'com.facebook.fresco:animated-gif:1.3.0'
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
I want to share that I noticed it crashes in android 4.4.4 version, but its not crashing in 5.0 version.. So anyone have some idea about it?..
I did all steps to show Google maps in android.
I have downloaded the newest version of Google play services , but still I have the below exceptions :
07-18 05:25:36.319: W/GooglePlayServicesUtil(2054): Google Play services is missing.
07-18 05:25:36.389: W/GooglePlayServicesUtil(2054): Google Play services is missing.
07-18 05:25:36.389: W/GooglePlayServicesUtil(2054): Google Play services is missing.
07-18 05:25:36.489: W/GooglePlayServicesUtil(2054): Google Play services is missing.
07-18 05:25:36.529: W/GooglePlayServicesUtil(2054): Google Play services is missing.
07-18 05:25:36.559: W/GooglePlayServicesUtil(2054): Google Play services is missing.
07-18 05:25:36.629: W/GooglePlayServicesUtil(2054): Google Play services is missing.
07-18 05:25:36.709: W/GooglePlayServicesUtil(2054): Google Play services is missing.
07-18 05:25:36.769: W/GooglePlayServicesUtil(2054): Google Play services is missing.
07-18 05:25:36.949: W/GooglePlayServicesUtil(2054): Google Play services is missing.
07-18 05:25:36.989: W/GooglePlayServicesUtil(2054): Google Play services is missing.
07-18 05:25:40.239: I/Choreographer(2054): Skipped 494 frames! The application may be doing too much work on its main thread.
07-18 05:25:44.689: D/gralloc_goldfish(2054): Emulator without GPU emulation detected.
07-18 05:25:55.930: D/AndroidRuntime(2054): Shutting down VM
07-18 05:25:55.930: W/dalvikvm(2054): threadid=1: thread exiting with uncaught exception (group=0xb1f58648)
07-18 05:25:56.010: E/AndroidRuntime(2054): FATAL EXCEPTION: main
07-18 05:25:56.010: E/AndroidRuntime(2054): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.google.android.gms flg=0x80000 pkg=com.android.vending }
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.app.Activity.startActivityForResult(Activity.java:3390)
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.app.Activity.startActivityForResult(Activity.java:3351)
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839)
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.app.Activity.startActivity(Activity.java:3587)
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.app.Activity.startActivity(Activity.java:3555)
07-18 05:25:56.010: E/AndroidRuntime(2054): at com.google.android.gms.dynamic.a$5.onClick(Unknown Source)
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.view.View.performClick(View.java:4240)
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.view.View$PerformClick.run(View.java:17721)
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.os.Handler.handleCallback(Handler.java:730)
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.os.Handler.dispatchMessage(Handler.java:92)
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.os.Looper.loop(Looper.java:137)
07-18 05:25:56.010: E/AndroidRuntime(2054): at android.app.ActivityThread.main(ActivityThread.java:5103)
07-18 05:25:56.010: E/AndroidRuntime(2054): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 05:25:56.010: E/AndroidRuntime(2054): at java.lang.reflect.Method.invoke(Method.java:525)
07-18 05:25:56.010: E/AndroidRuntime(2054): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-18 05:25:56.010: E/AndroidRuntime(2054): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-18 05:25:56.010: E/AndroidRuntime(2054): at dalvik.system.NativeStart.main(Native Method)
07-18 05:26:02.570: I/Process(2054): Sending signal. PID: 2054 SIG: 9
this is the manifest of my app i have added permisions and the api key:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tunivote"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<permission android:name="com.example.tunivote.MAPS_RECEIVE" android:protectionLevel="signature"></permission>
<uses-permission android:name="com.example.tunivote.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.example.tunivote.providres.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="my api key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="authentification"></activity>
</application>
</manifest>
Once check your emulator type, Whether it is Android or Google emulator. Please make sure your running on Google API Emulator.
I'm new to developing for Android and I'm having trouble launching my project. Whenever I launch it, it crashes and I get an error. I've put breakpoints throughout my code but it crashes before it reaches them. Here is the output from LogCat:
07-18 18:22:17.695: I/System.out(32229): Sending WAIT chunk
07-18 18:22:17.695: W/ActivityThread(32229): Application com.amvara.skatometer is waiting for the debugger on port 8100...
07-18 18:22:17.945: I/dalvikvm(32229): Debugger is active
07-18 18:22:18.095: I/System.out(32229): Debugger has connected
07-18 18:22:18.095: I/System.out(32229): waiting for debugger to settle...
07-18 18:22:18.295: I/System.out(32229): waiting for debugger to settle...
07-18 18:22:18.500: I/System.out(32229): waiting for debugger to settle...
07-18 18:22:18.700: I/System.out(32229): waiting for debugger to settle...
07-18 18:22:18.900: I/System.out(32229): waiting for debugger to settle...
07-18 18:22:19.100: I/System.out(32229): waiting for debugger to settle...
07-18 18:22:19.300: I/System.out(32229): waiting for debugger to settle...
07-18 18:22:19.500: I/System.out(32229): waiting for debugger to settle...
07-18 18:22:19.705: I/System.out(32229): debugger has settled (1434)
07-18 18:22:19.735: W/dalvikvm(32229): Unable to resolve superclass of Lcom/amvara/skatometer/ItemListActivity; (29)
07-18 18:22:19.735: W/dalvikvm(32229): Link of class 'Lcom/amvara/skatometer/ItemListActivity;' failed
07-18 18:22:19.745: D/AndroidRuntime(32229): Shutting down VM
07-18 18:22:19.745: W/dalvikvm(32229): threadid=1: thread exiting with uncaught exception (group=0x410d62a0)
07-18 18:22:19.780: E/AndroidRuntime(32229): FATAL EXCEPTION: main
07-18 18:22:19.780: E/AndroidRuntime(32229): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.amvara.skatometer/com.amvara.skatometer.ItemListActivity}: java.lang.ClassNotFoundException: com.amvara.skatometer.ItemListActivity
07-18 18:22:19.780: E/AndroidRuntime(32229): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2024)
07-18 18:22:19.780: E/AndroidRuntime(32229): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
07-18 18:22:19.780: E/AndroidRuntime(32229): at android.app.ActivityThread.access$600(ActivityThread.java:140)
07-18 18:22:19.780: E/AndroidRuntime(32229): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
07-18 18:22:19.780: E/AndroidRuntime(32229): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 18:22:19.780: E/AndroidRuntime(32229): at android.os.Looper.loop(Looper.java:137)
07-18 18:22:19.780: E/AndroidRuntime(32229): at android.app.ActivityThread.main(ActivityThread.java:4898)
07-18 18:22:19.780: E/AndroidRuntime(32229): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 18:22:19.780: E/AndroidRuntime(32229): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 18:22:19.780: E/AndroidRuntime(32229): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
07-18 18:22:19.780: E/AndroidRuntime(32229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
07-18 18:22:19.780: E/AndroidRuntime(32229): at dalvik.system.NativeStart.main(Native Method)
07-18 18:22:19.780: E/AndroidRuntime(32229): Caused by: java.lang.ClassNotFoundException: com.amvara.skatometer.ItemListActivity
07-18 18:22:19.780: E/AndroidRuntime(32229): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-18 18:22:19.780: E/AndroidRuntime(32229): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-18 18:22:19.780: E/AndroidRuntime(32229): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-18 18:22:19.780: E/AndroidRuntime(32229): at android.app.Instrumentation.newActivity(Instrumentation.java:1057)
07-18 18:22:19.780: E/AndroidRuntime(32229): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
07-18 18:22:19.780: E/AndroidRuntime(32229): ... 11 more
I can't figure out why this would happen because it isn't even hitting a breakpoint in my code. It must be a problem in the auto-generated Android code. Here's my AndroidManifest.xml, if you need it:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amvara.skatometer"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.amvara.skatometer.ItemListActivity"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.amvara.skatometer.ItemDetailActivity"
android:label="#string/title_item_detail"
android:parentActivityName=".ItemListActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ItemListActivity" />
</activity>
<activity
android:name="com.amvara.skatometer.Bottom_panel"
android:label="#string/title_activity_bottom_panel" >
</activity>
<activity
android:name="com.amvara.skatometer.General"
android:label="#string/title_activity_general" >
</activity>
<activity
android:name="com.amvara.skatometer.SettingsActivity"
android:label="#string/title_activity_settings" >
</activity>
</application>
</manifest>
Thanks.
Try to clean your project, then you can also change :
<activity
android:name="com.amvara.skatometer.ItemListActivity"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape" >
[...]
</activity>
By
<activity
android:name=".ItemListActivity"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape" >
[...]
</activity>
It append to me one time but after all modification, doesn't work so I recreate the project from scratch and imported all my class, layout, etc. At the end, works as well.
I watched Google IO 2011 conference, read almost every post about OutOfMemory Exception and InflateException, no luck, I cannot find any answer that solve my problem.
How can I properly clear memory from a layout containing a background image? I feel like if the InflateException followed by OutOfMemory are related because that background image is not cleared properly.
So I'm getting :
Android.Views.InflateException: Binary XML file line #24: Error
inflating class
followed by :
Java.Lang.OutOfMemoryError:
Which I'm pretty sure is caused by my background image.
I simplified my code to narrow the problem as much as possible.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="12" android:targetSdkVersion="12" />
<activity />
<application android:theme="#android:style/Theme.NoTitleBar" parent="android:Theme"/>
</manifest>
I added parent="android:Theme" which was suppose to fix the issue, no success.
SplashScreen.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/SplashScreenView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/splash" />
splash is a .png image located in my drawable folder.
SplashScreenActivity.cs
[Activity(Label = "My splash screen", MainLauncher = true)]
public class SplashScreenActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.SplashScreen);
StartNextActivity();
}
private void StartNextActivity()
{
var intent = new Intent(this, typeof(SplashScreenActivity));
intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);
StartActivity(intent);
Finish();
}
public override void Finish()
{
base.Finish();
var view = FindViewById<LinearLayout>(Resource.Id.SplashScreenView);
view.Background.SetCallback(null);
view.Background.Dispose();
view.DestroyDrawingCache();
Resources.FlushLayoutCache();
}
}
First I do load the SplashScreenActivity continuously, this is intentional to make the errors happen sooner.
As you can see, I tried several things to clear the Background image, setting flags or explicitly trying to dispose it.
On the first load I get those messages, which seems to be ok since it is loading the image :
07-18 12:14:22.472 I/dalvikvm-heap(30085): Grow heap (frag case) to 10.600MB for 2949136-byte allocation
07-18 12:14:22.522 D/dalvikvm(30085): GC_CONCURRENT freed 76K, 7% free 9432K/10119K, paused 2ms+1ms
However, it keep growing up until I consume all the device available memory :
07-18 12:12:17.852 I/dalvikvm-heap(18665): Clamp target GC heap from 68.605MB to 64.000MB
07-18 12:12:17.852 D/dalvikvm(18665): GC_FOR_ALLOC freed 73K, 1% free 65064K/65543K, paused 338ms
07-18 12:12:17.852 I/dalvikvm-heap(18665): Forcing collection of SoftReferences for 1576-byte allocation
07-18 12:12:18.212 I/dalvikvm-heap(18665): Clamp target GC heap from 68.604MB to 64.000MB
07-18 12:12:18.212 D/dalvikvm(18665): GC_BEFORE_OOM freed <1K, 1% free 65064K/65543K, paused 362ms
07-18 12:12:18.212 E/dalvikvm-heap(18665): Out of memory on a 1576-byte allocation.
07-18 12:12:18.212 I/dalvikvm(18665): "main" prio=5 tid=1 RUNNABLE
07-18 12:12:18.212 I/dalvikvm(18665): | group="main" sCount=0 dsCount=0 obj=0x40a45460 self=0xb068a0
07-18 12:12:18.212 I/dalvikvm(18665): | sysTid=18665 nice=0 sched=0/0 cgrp=default handle=1074517128
07-18 12:12:18.212 I/dalvikvm(18665): | schedstat=( 71462466000 19081532000 88403 ) utm=6360 stm=786 core=0
07-18 12:12:18.212 I/dalvikvm(18665): at android.content.res.Resources.getCachedStyledAttributes(Resources.java:~2193)
07-18 12:12:18.212 I/dalvikvm(18665): at android.content.res.Resources.access$000(Resources.java:71)
07-18 12:12:18.212 I/dalvikvm(18665): at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java:1260)
07-18 12:12:18.212 I/dalvikvm(18665): at android.content.Context.obtainStyledAttributes(Context.java:364)
07-18 12:12:18.212 I/dalvikvm(18665): at android.view.View.<init>(View.java:2746)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.ViewGroup.<init>(ViewGroup.java:385)
07-18 12:12:18.222 I/dalvikvm(18665): at android.widget.LinearLayout.<init>(LinearLayout.java:174)
07-18 12:12:18.222 I/dalvikvm(18665): at android.widget.LinearLayout.<init>(LinearLayout.java:170)
07-18 12:12:18.222 I/dalvikvm(18665): at java.lang.reflect.Constructor.constructNative(Native Method)
07-18 12:12:18.222 I/dalvikvm(18665): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
07-18 12:12:18.222 I/dalvikvm(18665): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-18 12:12:18.222 I/dalvikvm(18665): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2707)
07-18 12:12:18.222 I/dalvikvm(18665): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2767)
07-18 12:12:18.222 I/dalvikvm(18665): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:247)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.Activity.setContentView(Activity.java:1835)
07-18 12:12:18.222 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.n_onCreate(Native Method)
07-18 12:12:18.222 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.onCreate(SplashScreenActivity.java:30)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.Activity.performCreate(Activity.java:4465)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-18 12:12:18.222 I/dalvikvm(18665): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 12:12:18.222 I/dalvikvm(18665): at android.os.Looper.loop(Looper.java:137)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-18 12:12:18.222 I/dalvikvm(18665): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 12:12:18.222 I/dalvikvm(18665): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 12:12:18.222 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-18 12:12:18.222 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-18 12:12:18.222 I/dalvikvm(18665): at dalvik.system.NativeStart.main(Native Method)
07-18 12:12:18.222 I/dalvikvm(18665):
07-18 12:12:18.972 I/dalvikvm-heap(18665): Clamp target GC heap from 68.623MB to 64.000MB
07-18 12:12:18.972 D/dalvikvm(18665): GC_FOR_ALLOC freed 6K, 1% free 65082K/65543K, paused 341ms
07-18 12:12:18.982 I/dalvikvm-heap(18665): Forcing collection of SoftReferences for 1402-byte allocation
07-18 12:12:19.332 I/dalvikvm-heap(18665): Clamp target GC heap from 68.623MB to 64.000MB
07-18 12:12:19.332 D/dalvikvm(18665): GC_BEFORE_OOM freed <1K, 1% free 65082K/65543K, paused 358ms
07-18 12:12:19.332 E/dalvikvm-heap(18665): Out of memory on a 1402-byte allocation.
07-18 12:12:19.332 I/dalvikvm(18665): "main" prio=5 tid=1 RUNNABLE
07-18 12:12:19.332 I/dalvikvm(18665): | group="main" sCount=0 dsCount=0 obj=0x40a45460 self=0xb068a0
07-18 12:12:19.332 I/dalvikvm(18665): | sysTid=18665 nice=0 sched=0/0 cgrp=default handle=1074517128
07-18 12:12:19.342 I/dalvikvm(18665): | schedstat=( 72173821000 19107690000 88644 ) utm=6429 stm=788 core=0
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~94)
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:124)
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.StringBuffer.append(StringBuffer.java:278)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.StringWriter.write(StringWriter.java:123)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.doWrite(PrintWriter.java:623)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:601)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:579)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:660)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:722)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:691)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:31)
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.Throwable.printStackTrace(Throwable.java:329)
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.Throwable.printStackTrace(Throwable.java:305)
07-18 12:12:19.342 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.n_onCreate(Native Method)
07-18 12:12:19.342 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.onCreate(SplashScreenActivity.java:30)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.Activity.performCreate(Activity.java:4465)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-18 12:12:19.342 I/dalvikvm(18665): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 12:12:19.342 I/dalvikvm(18665): at android.os.Looper.loop(Looper.java:137)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 12:12:19.342 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-18 12:12:19.342 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-18 12:12:19.342 I/dalvikvm(18665): at dalvik.system.NativeStart.main(Native Method)
07-18 12:12:19.342 I/dalvikvm(18665):
Unhandled Exception:
Android.Views.InflateException: Binary XML file line #24: Error inflating class <unknown>
07-18 12:12:24.902 I/dalvikvm-heap(18665): Clamp target GC heap from 68.644MB to 64.000MB
07-18 12:12:24.902 D/dalvikvm(18665): GC_FOR_ALLOC freed 5K, 1% free 65105K/65543K, paused 377ms
07-18 12:12:24.902 I/dalvikvm-heap(18665): Forcing collection of SoftReferences for 1402-byte allocation
07-18 12:12:25.242 I/dalvikvm-heap(18665): Clamp target GC heap from 68.644MB to 64.000MB
07-18 12:12:25.242 D/dalvikvm(18665): GC_BEFORE_OOM freed 0K, 1% free 65105K/65543K, paused 345ms
07-18 12:12:25.242 E/dalvikvm-heap(18665): Out of memory on a 1402-byte allocation.
07-18 12:12:25.242 I/dalvikvm(18665): "main" prio=5 tid=1 RUNNABLE
07-18 12:12:25.242 I/dalvikvm(18665): | group="main" sCount=0 dsCount=0 obj=0x40a45460 self=0xb068a0
07-18 12:12:25.242 I/dalvikvm(18665): | sysTid=18665 nice=0 sched=0/0 cgrp=default handle=1074517128
07-18 12:12:25.242 I/dalvikvm(18665): | schedstat=( 72950645000 19154453000 88901 ) utm=6504 stm=791 core=0
07-18 12:12:25.242 I/dalvikvm(18665): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~94)
07-18 12:12:25.242 I/dalvikvm(18665): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:124)
07-18 12:12:25.242 I/dalvikvm(18665): at java.lang.StringBuffer.append(StringBuffer.java:278)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.StringWriter.write(StringWriter.java:123)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.PrintWriter.doWrite(PrintWriter.java:623)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:601)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:579)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:660)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:722)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:691)
07-18 12:12:25.252 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:31)
07-18 12:12:25.252 I/dalvikvm(18665): at java.lang.Throwable.printStackTrace(Throwable.java:329)
07-18 12:12:25.252 I/dalvikvm(18665): at java.lang.Throwable.printStackTrace(Throwable.java:305)
07-18 12:12:25.252 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.n_onCreate(Native Method)
07-18 12:12:25.252 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.onCreate(SplashScreenActivity.java:30)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.Activity.performCreate(Activity.java:4465)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-18 12:12:25.252 I/dalvikvm(18665): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 12:12:25.252 I/dalvikvm(18665): at android.os.Looper.loop(Looper.java:137)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-18 12:12:25.252 I/dalvikvm(18665): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 12:12:25.252 I/dalvikvm(18665): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 12:12:25.252 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-18 12:12:25.252 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-18 12:12:25.252 I/dalvikvm(18665): at dalvik.system.NativeStart.main(Native Method)
07-18 12:12:25.252 I/dalvikvm(18665):
07-18 12:12:26.042 I/dalvikvm-heap(18665): Clamp target GC heap from 68.654MB to 64.000MB
07-18 12:12:26.042 D/dalvikvm(18665): GC_FOR_ALLOC freed 4K, 1% free 65114K/65543K, paused 395ms
07-18 12:12:26.042 I/dalvikvm-heap(18665): Forcing collection of SoftReferences for 1126-byte allocation
07-18 12:12:26.392 I/dalvikvm-heap(18665): Clamp target GC heap from 68.654MB to 64.000MB
07-18 12:12:26.392 D/dalvikvm(18665): GC_BEFORE_OOM freed 0K, 1% free 65114K/65543K, paused 344ms
07-18 12:12:26.392 E/dalvikvm-heap(18665): Out of memory on a 1126-byte allocation.
07-18 12:12:26.392 I/dalvikvm(18665): "main" prio=5 tid=1 RUNNABLE
07-18 12:12:26.392 I/dalvikvm(18665): | group="main" sCount=0 dsCount=0 obj=0x40a45460 self=0xb068a0
07-18 12:12:26.392 I/dalvikvm(18665): | sysTid=18665 nice=0 sched=0/0 cgrp=default handle=1074517128
07-18 12:12:26.392 I/dalvikvm(18665): | schedstat=( 73695992000 19195168000 89137 ) utm=6574 stm=795 core=0
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~94)
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:124)
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.StringBuffer.append(StringBuffer.java:278)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.StringWriter.write(StringWriter.java:123)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.doWrite(PrintWriter.java:623)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:601)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:579)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:660)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:722)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:691)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:31)
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.Throwable.printStackTrace(Throwable.java:329)
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.Throwable.printStackTrace(Throwable.java:305)
07-18 12:12:26.392 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.n_onCreate(Native Method)
07-18 12:12:26.392 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.onCreate(SplashScreenActivity.java:30)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.Activity.performCreate(Activity.java:4465)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-18 12:12:26.392 I/dalvikvm(18665): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 12:12:26.392 I/dalvikvm(18665): at android.os.Looper.loop(Looper.java:137)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 12:12:26.392 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-18 12:12:26.392 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-18 12:12:26.392 I/dalvikvm(18665): at dalvik.system.NativeStart.main(Native Method)
07-18 12:12:26.392 I/dalvikvm(18665):
Unhandled Exception:
Java.Lang.OutOfMemoryError:
Additional information
The image is full screen and is the perfect size for this device (I mean that we don't want to shrink it). 1024x720, 24 bits, not Alpha and it takes 487KB on my disk, but obviously, when Android loads it, it seems to be around 10 MB.
I'm running the code on a Nabi2 tablet, model : NABI2-NV7A which is running Android version 4.0.4 along with Kernel version 3.1.10-00275-g3a4f8c1.
Also note that in Visual Studio in my Application Properties, I am targetting those Android versions:
OK, I found a way to do this without throwing these errors.
Instead of creating a Layout with the Splash Screen, I created a theme, since in your case it is simply an image anyways:
styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="SplashTheme" parent="#android:style/Theme.NoTitleBar">
<item name="android:background">#drawable/kitten</item>
</style>
</resources>
Then I created an Activity like this:
using Android.App;
using Android.Content;
using Android.OS;
namespace SplashScreenSample
{
[Activity(Label = "Splushy Splushy", MainLauncher = true, Theme = "#style/SplashTheme")]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle b)
{
base.OnCreate(b);
StartNextActivity();
}
private void StartNextActivity()
{
var intent = new Intent(this, typeof(SplashActivity));
intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearWhenTaskReset);
StartActivity(intent);
Finish();
}
}
}
I tried running this on my phone for 10 minutes or so, without any crash with an image of 1600x1200 of a nice kitten.
I found another solution that helped, but never as much as Cheesebaron's solution.
In both cases, it end up crashing.
Cheesebaron's solution crashes after : 14 minutes
Mine crashes after 3 minutes 28 sec.
Since I'm looping intensively to push the device to its limit, Cheesebaron's solution is surely viable.
In my case, instead of setting android:background="#drawable/splash", I removed that entry and used a private Bitmap field in my activity which I then load and pass it to the background drawable.
private Bitmap _bitmapRef;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var view = FindViewById<LinearLayout>(Resource.Id.SplashScreenView);
_bitmapRef = BitmapFactory.DecodeResource(Resources, Resource.Drawable.splash, new BitmapFactory.Options
{
InPurgeable = true,
InInputShareable = true
});
view.SetBackgroundDrawable(new BitmapDrawable(Resources, _bitmapRef));
StartNextActivity();
}
Then, on the OnDestroy call, I override it to explicitly recycle the bitmap.
protected override void OnDestroy()
{
base.OnDestroy();
if (null != _bitmapRef && !_bitmapRef.IsRecycled)
{
_bitmapRef.Recycle();
_bitmapRef = null;
}
}
It seems to me like if Android have problems when the Bitmap is created at the Activity level.
I have another activities in which I load bitmaps in a list object to display them on screen. The list object is at the Activity level and the bitmaps are inside the list.
In that case, the memory seems to be handled properly when I use the above solution. I don't even have to call recycle on the bitmaps inside the list.
But for the SplashScreen, that solution doesn't seems to be enough.
I have UnknownHostExeption, when i am using proxy. My App works finy in networks without proxy or with some proxies( not everyone).
I am aware that I need to setup proxy setings for networks with them
for device: wify settings - advance - wifi proxy
emulator: wireless networks - mobile networks - access points - telkia - proxy|port.
I wish to know which essential options I have to ask admins to unlock for stable network comunications.
07-18 08:51:26.780: W/System.err(302): java.net.UnknownHostException: mirkvartir.ua
07-18 08:51:26.780: W/System.err(302): at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
07-18 08:51:26.780: W/System.err(302): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
07-18 08:51:26.780: W/System.err(302): at java.net.InetAddress.getAllByName(InetAddress.java:242)
07-18 08:51:26.780: W/System.err(302): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
07-18 08:51:26.780: W/System.err(302): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
07-18 08:51:26.780: W/System.err(302): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
07-18 08:51:26.780: W/System.err(302): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
07-18 08:51:26.780: W/System.err(302): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-18 08:51:26.780: W/System.err(302): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-18 08:51:26.780: W/System.err(302): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-18 08:51:26.780: W/System.err(302): at ua.mirkvartir.android.frontend.adapter.JSONParser.getJSONFromUrl(JSONParser.java:98)
07-18 08:51:26.780: W/System.err(302): at ua.mirkvartir.android.frontend.adapter.UserFunctions.loginUser(UserFunctions.java:76)
07-18 08:51:26.787: W/System.err(302): at ua.mirkvartir.android.frontend.LoginActivity$Login.doInBackground(LoginActivity.java:185)
07-18 08:51:26.787: W/System.err(302): at ua.mirkvartir.android.frontend.LoginActivity$Login.doInBackground(LoginActivity.java:1)
07-18 08:51:26.787: W/System.err(302): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-18 08:51:26.787: W/System.err(302): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-18 08:51:26.787: W/System.err(302): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-18 08:51:26.787: W/System.err(302): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
07-18 08:51:26.787: W/System.err(302): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
07-18 08:51:26.787: W/System.err(302): at java.lang.Thread.run(Thread.java:1096)
Answer is, you cannot tell in general. This is not Android-specific, but depends on your App. You're free to choose the ports it communicates over. Usually, 80 and 443 shouldn't be blocked (http / https) - everything else depends on your App.
What services do you use? If you never specified a port explicitly, they might imply one.