Main layout makes lags - Java for Android App Development

Hello guys!
Here is my new problem. When I add background image to my main layout (RelativeLayout) my listView, and horizontalScrollView (they are both on my main page) are taking lags and they stopped moving smoothly. I dont know what can i do, please help.

Matma said:
Hello guys!
Here is my new problem. When I add background image to my main layout (RelativeLayout) my listView, and horizontalScrollView (they are both on my main page) are taking lags and they stopped moving smoothly. I dont know what can i do, please help.
Click to expand...
Click to collapse
Try switching all the operation to other threads and keep the main thread only for displaying only GUI related stuff.
Sent from my Moto G using XDA Free mobile app

Since you've mentioned a background image, I would make sure that it's both a reasonable size and that you aren't setting it over and over again. Lots of bitmap processing really slows down Android apps because it's very computationally expensive compared to everything else.

maclynb said:
Since you've mentioned a background image, I would make sure that it's both a reasonable size and that you aren't setting it over and over again. Lots of bitmap processing really slows down Android apps because it's very computationally expensive compared to everything else.
Click to expand...
Click to collapse
Exactly. id be looking at the filesize before anythibg else though.

Related

[GUIDE] About Android and Optimizing Sony Xperia X10

Since Sony Xperia X10 is now running on 2.1, topics related to 1.6 is not mentioned here.
This thread are created based on compilation of other threads related to optimization, and meant as an entry point for user interested in optimization.
Understanding your Android
Just to put something short, so we can understand our Android and some points related to optimization better.
Android is an open source operating system owned by Google that is maintained by Android Open Source Project (AOSP). The operating system is based on modified Linux kernel, where most of the application is written in Java language and running on DalvikJVM.
Android do things differently than old generation OS like Symbian, and below is the explanation related to performance.
Unlike Symbian, Android designed to have as many as application loaded and running in the OS, it maintain list of least used application that will be unloaded when a requests for more memory is made when the free OS memory is already low.
These are the nature of JVM, where allocation and deallocation of memory is managed by garbage collector as doing things in bulk is faster then working with small chunks. So you don't have to be alarmed when you open a memory viewer application and see your Android is running on low memory. Freeing RAM with task killer is only momentarily, as you uses the phone again, the free memory will goes down again.
Android phones stores system application, data and files internally in NAND flash area and stores user data in internal memory storage or external storage such as SD cards. This memory is different than your operating sytem memory.
Operating system memory is memory allocated for the kernel, native application and most application you download from market. Installing a lot of application will not directly reduce free RAM, nor uninstalling or removing files will increase free RAM directly. Action such as removing ringtones, wallpaper and even Sony PC Companion ISO will not free your RAM
In general there are two type of android application. One is a standalone application that only run if you open the application, and the other one is running even you haven't open the application which called service.
By design, guideline and suggested practice, application should not continue to run lengthy processing when it get pushed to background via home button, back button or switching to other application; properly build application will just go idle. Which means you should be less paranoid about application eating you processing power.
But service is meant to run lengthy operation as they don't have user interface and runs in background. Some service meanth for pushing or pulling data from internet, reading your files and do processing like playing songs, or just doing something then update the widget just to make you happy. Unnecessary services are the things that you should be aiming if you want to optimize your Android.
General FAQ about Optimizing Sony Xperia X10 2.1
I just updated to 2.1 and my phone really feel slower than 1.6
Since you had been using 1.6 for quite some time, your SD card should have quite a lot of photo and media. Just after you updated to 2.1, and add your Google and maybe Facebook account, the new Face Recognition service is actually already starting to scans all your photo, then when your Google and Facebook contact arrived, it will try it best to match photo and contact. This new Face Recognition really kicks hard in your processor, then after a while your phone will be as fast and even better than old stock 1.6.
I still feel that the phone is slow, is there any simple and quick way to optimize
The simple and quick to optimize your phone instantly is by changing the 2.1 dalvikvm to JIT capable dalvikjvm. You can read and apply them by reading the thread referred below, but before you do that open the below link in background tab and please do read more first.
Android 2.1 OPTIMISER V002 by Jerpelea
2.1 Customizer v0.99.1 by ttxdragon
Both optimizer contains script that will erase your "junk/unused" application from your phone, be sure to read them first before executing. My suggestion is you apply JIT modification first, before going optimizing by remove your "junk/unused" application.
Please do remember that you have to Root your X10 first.
How to root the phone
You can root the phone using methods below.
OneClick z4root Android Application
SuperOneClick Windows Application
Is [INSERT APP NAME] here is save to remove?
By removing unused application, you will gain certain amount of performance gain. Below are the links with app list.
2.1 Customizer v0.99.1 by ttxdragon
Official List of Apps that Can be Removed from a 2.1 x10 by exekias
And still a lot more in other Sony Ericsson X10 forum section but those two is quite complete
And in case you forgot to make backup you can go to
2.1 System Apps - In Case You've Deleted Them by XperiaX10iUser
After doing all that my Quadrant Benchmark is still low
You should run Quadrant as least two or three time or until you get best score, the first one usually yield low score, because a lot of memory allocation process to Quadrant happening during the first run.
Tuning Utilities
Memory Usage - Application to see how much memory used by your application and services
Advanced Task Manager - Application to see is your application running on foreground, background or idle and its memory usage
Quadrant Standard - General benchmarking tools to see if your changes make improvement
Linpack - Processor benchmarking
Titanium Backup Pro - Back up application, the paid version can freeze your app rather then uninstalling it.
Fine Tuning Guide
About Widget, Application shortcut and Live Wallpaper
Even though widgets looks really good in your phone, some widgets required simple periodic process for updating its display, some have a full blown service running to support it. A very instant example that you can see in your phone is the Power Control widget and the new Status Switch widget.
Power Control widget update triggered by configuration change such as wifi on and off, while Status Switch widget which have a battery level is triggered by a running service. Just put Status Switch widget then go to Settings -> Application -> Running Services. Then you will see there a Status Switch Update service running in background to update the battery level.
By selectively put widgets on your home screen, you can gain extra processing and memory. Timescape widget is even worse, it have three service running to support it.
Application shortcuts also uses extra memory in your home screen app and your home screen app is usually system persistent, reducing number of shortcut will give extra RAM and reducing the required rendering process during scroll.
Live Wallpaper just as the name said looks really nice and require extra memory and process of course.
Tuning via build.prop
Some value can be added and modified into build to increase the performance of X10.
dalvik.vm.heapsize=32m
This will change the maximum memory size per application. If you decrease the value, smaller application starts faster, but big application like games will prone to crash, if you increase the value too much, smaller application takes longer to start, but big application will extra gain benefit from less garbage collecting.
Reference: Test: How changing the max amount of memory per VM Heap can effect your ROM (Cyanogen)
windowsmgr.max_events_per_sec=60
This will change the maximum number of touch screen gesture events per second, the bigger the value, the smoother the scrolling will be
There still some more build.prop tweaks that you can do, but not all of them will be processed by X10 as each device behave differently.
reservation for more article to go
Nice clean guide, should help newcomers. Good work!
synlar said:
Nice clean guide, should help newcomers. Good work!
Click to expand...
Click to collapse
Thanks, but i am quite depressed after reading it my self and found that i make a lot of typo. Had to revise and revise again.. lol.
Nice piece of work there Xeviro..
Can you post your build.prop please i cant find the windowsmgr.max_events_per_sec=60 one in mine.
Wolfbreak said:
Can you post your build.prop please i cant find the windowsmgr.max_events_per_sec=60 one in mine.
Click to expand...
Click to collapse
That one you add by your self to you build.prop. If you look further in google, there still a lot of other build properties that you can set to Android.
There is another way to add and test build.prop instantly by using adb shell command "setprop key value" and "getprop key". Some property will take effect immediately, some require you to reboot.
How do you prove that the windowsmgr.max_events_per_sec=60 actually works? After applying that I tried input benchmark and it still showed 33hz.
ooidort said:
How do you prove that the windowsmgr.max_events_per_sec=60 actually works? After applying that I tried input benchmark and it still showed 33hz.
Click to expand...
Click to collapse
Ok, i just checked, that for this build.prop property to take effect, you need to reboot the device first. I just test on my, giving 10 and 200 in value. With 10, the input benchmark showing less then 20hz most of the time, while with 200 it gives me 40hz+.
Also you can see if you scroll the app list with 10 and 200 value, you can see the difference.
xeviro said:
Ok, i just checked, that for this build.prop property to take effect, you need to reboot the device first. I just test on my, giving 10 and 200 in value. With 10, the input benchmark showing less then 20hz most of the time, while with 200 it gives me 40hz+.
Also you can see if you scroll the app list with 10 and 200 value, you can see the difference.
Click to expand...
Click to collapse
I definitely notice the difference between 10 and 200, but it still doesn't go above 33hz... Maybe it's the framerate cap doing it's thing?
xeviro said:
Thanks, but i am quite depressed after reading it my self and found that i make a lot of typo. Had to revise and revise again.. lol.
Click to expand...
Click to collapse
Good write up! I was actually going to say something about the typos/errors, because I'm a jerk, but, you noticed them too, so I feel satisfied.
I hope people will read your little intro about RAM and realize a task killer's real purpose is to kill rogue services that kill battery.
xeviro said:
That one you add by your self to you build.prop. If you look further in google, there still a lot of other build properties that you can set to Android.
There is another way to add and test build.prop instantly by using adb shell command "setprop key value" and "getprop key". Some property will take effect immediately, some require you to reboot.
Click to expand...
Click to collapse
But where do i need them to add? At Beginning or at End or Middle?
iead1 said:
Good write up! I was actually going to say something about the typos/errors, because I'm a jerk, but, you noticed them too, so I feel satisfied.
I hope people will read your little intro about RAM and realize a task killer's real purpose is to kill rogue services that kill battery.
Click to expand...
Click to collapse
Please forgive my typo and grammars, i life in country where people simplify their way of communication. I cannot talk proper now. hahaha
Wolfbreak said:
But where do i need them to add? At Beginning or at End or Middle?
Click to expand...
Click to collapse
Anywhere
xeviro said:
Please forgive my typo and grammars, i life in country where people simplify their way of communication. I cannot talk proper now. hahaha
Anywhere
Click to expand...
Click to collapse
If i add this to the end of my build.prop my phone does not accept SIM unlock code anymore .... ??
EDIT: Strange, second time it worked ... btw. what is the default value ?
Ive added dalvik.vm.heapsize=32m to see what diff it will make and well..
wow.. it killed my phone.
It will show sony ericsson on the screen when you turn it on and just stay there!
So yeah... how can i fix this?
It's bricked, you'll need to reflash the software!
:-(
OP- Great thread, thank you!
Post on my Rooted 2.1 X10i using Tapatalk Pro and Swype
Yeah i knida noticed...
fixed now but im not trying that heapsize thing again..
Anyone here have the original/untouched nordic build.prop? I'm really appreciate it if you share it here. ^_^
Sent from my Xperia X10i (2.1 and rooted) using XDA app
Seansmit17 said:
Ive added dalvik.vm.heapsize=32m to see what diff it will make and well..
wow.. it killed my phone.
It will show sony ericsson on the screen when you turn it on and just stay there!
So yeah... how can i fix this?
Click to expand...
Click to collapse
Seansmit17 said:
Yeah i knida noticed...
fixed now but im not trying that heapsize thing again..
Click to expand...
Click to collapse
Its working correctly in my phone, and this heapsize settings is the most common one in android modding. you go check google and see the results.
I also attached build.prop from my phone.

Help with memory leak

Hey guys. I've been looking around all over for info on the problem with my app. Nothing I found was a concrete answer. here's the problem. I made an app that works really well except it force closes when I hit the back button to finish activity and then start another of the same activity as before. It force closes once in a while when I do this, throwing a log cat error that says out of memory, pointing to where I fill my bitmap cache. There's two reasons im thinking it would be doing this. 1) My bitmap factory is having a problem or 2) I have the context of my activity stored as a variable so I can close activity and that is too much memory. I'm using a panel, which also may add to the problem. Also, another phone can't even start the activity the first time. Any help would be greatly appreciated. This is only problem on app and this fix will make it market ready.
Sent from my SCH-I500 using XDA App
Did you try to explicitly clean up the bitmap references? you should call Recycle() on every bitmap in your activity's onDestroy or wherever you do your cleaning. Another issue I had was with the Bitmap.CreateScaledBitmap method - it leaks, apparently. I made a small static method that uses a transform matrix and then calls Bitmap.CreateBitmap (the overload that takes a matrix, obviously). That change alone solved half my memory issues.
The thing about not loading at all on another phone might be a heap issue. My game loaded just great on my customized SGS, but on the emulator with 24mb of heap it crashed. The reason was that I pre-load all the sprites at the beginning, and apparently 24mb isn't that much
Solution was downscaling and lowering resolution and color depth for the sprites, not much possibilities here - too many bitmaps take too much memory...
I'm guessing the phone you tested likely has a smaller heap than the phone that doesn't make your app crash.
Of course all of the above is mostly guess work, but that's what I can supply right now
i have the problem fc too, but after i upgraded to 2.2. the seem the problem fixed automatically.
Thanks so much! I made it recycle my bitmaps, along with a few minor changes, and it worked great! Thanks for your help!
Sent from my SCH-I500 using XDA App

[Q] How to make an app theme-able by another app?

Before you start saying that I'm posting in the wrong section, hear me out, I'm not asking about how to make themes or how to alter existing themes
I want to know how to write an app that is completely self contained application but can have its visual appearance and behavior altered when other apps are also installed on the same phone.
I'm pretty sure this functionality can be achieved b/c there are soo many theme apps in the market for ADW Launcher.
Does anyone know how to do this, and where I can find documentation about this kind of functionality?
I'm curious about this too. My best guess at the moment though is to make sure all of your UI controls are drawables, not just stock spinners / sliders / etc. Use drawables for the graphics in the UI, and when you publish your apk, those resources should be not only visible but changeable by others. Then again, I'm not 100% sure, so don't quote me on that lol.
parabola949 said:
I'm curious about this too. My best guess at the moment though is to make sure all of your UI controls are drawables, not just stock spinners / sliders / etc. Use drawables for the graphics in the UI, and when you publish your apk, those resources should be not only visible but changeable by others. Then again, I'm not 100% sure, so don't quote me on that lol.
Click to expand...
Click to collapse
Oops i quoted you... i think you are right though. It'll be links to different drawable resources
From something awesome

Apps Confusing the Note as a Full Size Tablet

Has anyone else run into this problem? Care to list such apps?
Google Music's interface is much different on the Note than it is on an S2 (at least for me). Where on the S2 artists, albums, etc are displayed in a long list of names, on the Note they are displayed in a long list of thumbnails of the artist, album, etc. This layout would make sense on a full size tablet and horizontal scrolling but it is very inefficient on the Note. Also much more taxing on the hardware (not that the Note is lacking in this department though). I would much prefer the S2's layout to quickly find an artist or scroll through the list.
Swiftkey X gives a warning when installed saying the phone version is incorrect for this device (the Note), use the tablet version. However, skipping the warning is not detrimental and the phone version works perfectly on the Note (have not tried the tablet version).
I assume this has to do with the resolution of the Note and apps confusing it as a Full Size Tablet. Anybody else seen this problem? On what apps? Workarounds?
JoyR2 said:
Has anyone else run into this problem? Care to list such apps?
Click to expand...
Click to collapse
I don't know if it's a 'problem'.
I don't necessarily like it with certain programs (some games are a bit painful to play), but I don't consider it a bug or anything.
It's a matter of detected screen resolution and how the app decides to use it. I don't see any workaround for it, unlike windows where you can use a selected resolution.
It would be nice for there to be an option to set screen resolution.
I imagine there are some people interested in the note because they want the larger size (larger icons/text/buttons/etc) but not necessarily the higher resolution. You can't always set that.
- Frank
it has full tablet resolution so it should run like that
kromosto said:
it has full tablet resolution so it should run like that
Click to expand...
Click to collapse
Ya, I know. But for some apps it really is not optimal. Just trying to get a feel for how many apps are going to encounter this "problem" (for lack of a better word).
Use spare parts to make the adjustment
Sent from my ADR6400L using xda premium
Plume thought that my note was a tablet. However the support team gave me a corrected version and said that it will be sorted in their next release

Instagram, Weheartit etc is getting closed.

When i use those 2 apps and when i load too much images (more than 1 minute of viewing) Instagram or weheartit or tumblr is getting closed. It's something about too much images loaded but what causes that? RAM much unused. I have space in ROM. What the? I have rooted ANG2. Before root i had the same problem. It makes me nervous that giant phone like S5 is clossing apps if too much pictures is being saw.
Phalcore said:
When i use those 2 apps and when i load too much images (more than 1 minute of viewing) Instagram or weheartit or tumblr is getting closed. It's something about too much images loaded but what causes that? RAM much unused. I have space in ROM. What the? I have rooted ANG2. Before root i had the same problem. It makes me nervous that giant phone like S5 is clossing apps if too much pictures is being saw.
Click to expand...
Click to collapse
Or maybe the app isn`t fully compatible with the S5 and causes fc`s!
It happen everytime with other apps displaying photos. Tinder or Weheartit... Its like - i loaded too much images and app is getting closed
Any solution? It makes me really angry.
More details, i got this in Reporting window:
Crash
Exception class name java.lang.OutOfMemoryError
Source file BitmapFactory.java
Source class android.graphics.BitmapFactory
Source method nativeDecodeStream
Line number -2
Any help? I have this on every firmware...

Categories

Resources