Posts

Showing posts with the label Android

Running old Android Studio without Java 6

From  http://tools.android.com/tech-docs/configuration : You can also place use environment variables to point to specific override files elsewhere: STUDIO_VM_OPTIONS , which vmoptions file to use STUDIO_PROPERTIES , which property file to use STUDIO_JDK , which JDK to run studio with Note that this last variable allows you to for example run Android Studio with Java 7 on OSX (which normally picks Java 6 from the version specified in  Info.plist ): $ export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk $ open /Applications/Android\ Studio.app

Activity life cycle

From http://androidcookbook.com/Recipe.seam?recipeId=2688 onSaveInstanceState(Bundle) and onPause() Use onPause to save data that should be preserved long term, use onSaveInstanceState for transient states. For example in a game the current score could be saved in onSaveInstanceState and only saved in onPause if it was good enough for the High Score table, in which cause the High Score table (in SharedPreferences, a database table, or a file) is updated. onSaveInstanceState\onRestoreInstanceState and the Android Lifecycle The SDK documentation says that  onSaveInstanceState(Bundle)  may run just before or just after  onPause() . As for onRestoreInstanceState(Bundle)  that occurs after  onStart()  and before  onResume(). onSaveInstanceState() is not called when the user navigates to another activity. So if the user presses the back button, this callback won't be called. But if the Android home button is pressed this callback is call...

Multi Threading in Android

It is good practice to not do computation intensive work on the UI Thread. In fact starting from HoneyComb, you get a NetworkOnMainThread exception if you try and do any network processing on the main thread. So we should do background work in a new thread. One thing we need to consider is that only the UI thread can update the UI, so when our background thread wants to update the UI, we need a means to communicate between threads. Actually even your background thread can update the UI, but this is really dangerous and your app can crash! Android provides a lot of multi threading constructs for us. AsyncTask is by far the easiest way of multithreading in Android. When you create a new AsyncTask object the framework creates a new thread for you and provides methods to communicate with the UI. No threads, no handlers and no Executors (Because it uses these classes internally)! So why not use AsyncTask all the time? Well, because these are suited for background work that typically l...

Unable to update Android SDK on Windows?

Some things I had to try to get it to work: Close Eclipse and any other folder that had the android sdk folder opened. Go to /tools Right click on android.bat and select 'Run as Administrator' This should work and you should be able to update the SDK now. If not, well you are screwed...

Logging from native service in Android

To log to a text file from a native daemon process, push the empty file beforehand to /data. Next check that the owner of the process and the location where you are writing are the same.

Busybox on android

This link seems to work http://benno.id.au/blog/2007/11/14/android-busybox Though we have to add busybox to the PATH each time.

Compiling AOSP

Before your images run successfully, y ou need to import the proprietary drivers. So if you want to compile gingerbread and let’s say you need to run it on a Nexus 1, you need to take an original Nexus 1 with gingerbread and import the drivers.  To do this connect the original Nexus One to your build machine and run “ /device/htc/passion/extract-files.sh. If you dont have a device with you, drivers can be downloaded as well. Go to  https://developers.google.com/android/nexus/drivers  and grab the tar files from there. Untar them in the root folder of your android source and run all of them. This should create a vendor folder with the device you need.

Android devices

Taken from  https://sites.google.com/site/androidopenkangproject/downloads-1/downloads  maguro  GSM Galaxy Nexus  toro  LTE Galaxy Nexus  crespo  Nexus S   crespo4g  Nexus S 4G  p4  Galaxy Tab 10.1" - 3G (P7500)  p4vzw  Galaxy Tab 10.1" - Verizon   p4wifi  Galaxy Tab 10.1" - Wi-Fi  stingray  Motorola Xoom - Verizon  wingray  Motorola Xoom - Wi-Fi   tenderloin   HP Touchpad   vivow  HTC Incredible 2  supersonic  HTC Evo 4G  inc  HTC Incredible   vzwtab  Galaxy Tab 7" - Verizon In addition Nexus 7 is called grouper Now these were the devices. Next we have boards. These board names are used when we compile the kernel using the _defconfig command. You can retrieve them by going into the bootloader of your phone Nexus One:       Mahimahi Nexus S    : ...

Good Android Links

http://www.vogella.com/articles/AndroidListView/article.html#listsactivity_simpleadapter

A binary with debug symbols with the Android NDK

First go into the Android.mk file in your jni folder and add this line: LOCAL_CFLAGS  += -g This is going to enable the debug compile option. You might have a separate option for logging more data. Next go into Application.mk and uncomment this line: APP_OPTIM := debug (or add it if it isnt there) This should be sufficient. Now when you run the ndk-build (You can run ndk-build V=1 to enable the verbose option), you should get the debuggable binaries. For some reason the binary I get in the libs/armeabi folder is not the debuggable one, this one has its debug options stripped out. To get the debug one grab it from obj/local/armeabi.

Debugging an android crash

Image
So lets say one of your android app crashes and you get something like this in your logcat: Here #00 tells us the address in the program counter. But this information is pretty useless. To translate into actual file and line numbers we can use a tool called addr2line. For NDK4 it is located at android-ndk-r4b/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin. For NDK5 it is at a different location. So we go to this location and run the tool: addr2line -f -e mydroid/gingerbread_2.3.3_GINGERBREAD/modified/out/target/product/crespo/symbols/system/lib/libmedia.so 0004853a This gives us the file and line numbers we are looking for. We use the code in the symbols directory because that has the unstripped version of the libraries.

kernel logs android

If you want to extract kernel logs from the android shell and are getting 'Permission Denied' errors, you can use this approach: Go into the adb shell and run: cat /proc/last_kmsg >/sdcard/last_kmsg. Now come out of the shell and run: adb pull /sdcard/last_kmsg This will extract the logs to the folder containing the adb exe!