This talk will focus on techniques that both libraries and applications can implement to ensure their effect is in general without overhead. It’s a really good stuff to Android developers and those Java developers whether they are doing android or not.
CPU
Do not nest multi-pass layouts
Lazily compute complex data when needed
Cache heavy computational results for re-use
Consider RenderScript for performance
Keep work off the main thread
Memory
Use object pools and caches to reduce churn
Be mindful of the overhead of enums
Do not allocate inside the draw path
Use specialized collections instead of JDK collection when appropriate (SparseArray)
notice there is no key word ‘break’ inside the switch block, therefore, no matter which version that user installed, the db update will be ran properly, and keep the database up to date.
Sometimes we need our services to do the work but they often were killed by something like a app management tool, here’s some tricks might help.
Service Flag
Set to START_STICKY, after around 5 sec of service being killed, it will restart, and pass Intent again.
1 2 3 4 5
@Override publicintonStartCommand(Intent intent, int flags, int startId){ flags = START_STICKY; returnsuper.onStartCommand(intent, flags, startId); }
Use startForeground
Use the startForeground(int, Notification) API to put the service in a foreground state, where the system considers it to be something the user is actively aware of and thus not a candidate for killing when low on memory. (It is still theoretically possible for the service to be killed under extreme memory pressure from the current foreground application, but in practice this should not be a concern.) [From official doc]
Twin Service
Create 2 services to protect each other. they will restart the other service when it was killed.
Evil Trick [Have not tried it yet]
Remain 1px size page in the foreground to stay in a foreground state when application goes to background.
Disguise App as system app [Android 4.0]
Install your apk into /system/app. Make your app as a system app by changing the proper permissions in a rooted device.
White List
Contact manufacturer.
Listen To The Broadcast
1 2 3 4 5 6 7 8
<receiverandroid:name="<Name of your package>.<your class>" > <intent-filter> <actionandroid:name="android.intent.action.BOOT_COMPLETED" /> <actionandroid:name="android.intent.action.USER_PRESENT" /> <actionandroid:name="android.intent.action.PACKAGE_RESTARTED" /> <actionandroid:name="<Name of your package>.<your class>" /> </intent-filter> </receiver>
BroadcastReceiver,
1 2 3 4 5 6 7 8 9 10
@Override public void onReceive(Context context, Intent intent) { if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { //start your sercice startUploadService(context); } if(Intent.ACTION_USER_PRESENT.equals(intent.getAction())) { //... } }
You could use Intent.ACTION_TIME_TICK as better result, this one broadcasts in every minute, however it’s a system broadcast, you can’t config it in manifest.xml, register it in your service or App extends application,
When I start a virtual device, why does the window remain black?
The offical Q&A will give you this
You are probably in either of the following situations:
Your network adapter may be misconfigured. In this case:
Run VirtualBox.
Open File > Preferences > Network (or VirtualBox > Preferences for Mac OS X).
Edit the Host-only Network by clicking .
Check that the adapter IPv4 address is in the same network (192.168.56.0/24 by default) as the DHCP server address, lower address bound and upper address bound. If not, your virtual device cannot start. You can also remove the Host-only Network by clicking . Genymotion will automatically recreate it at the next virtual device start.
Your firewall may block the application. The Genymotion application must connect to the virtual device via the local network. If you have a firewall, make sure that you allowed connections to the Genymotion network, set to 192.168.56.0/24 by default. You can also check the log files to see whether an error occurred. To do so, please refer to How do I generate an archive containing Genymotion logs of a virtual device?. If there is no error, restart your virtual device directly from the VirtualBox application.
Have you met this problem when you use genymotion? I met this problem months ago, when I tried to make it work by following above, I failed. and then I forgot to post my solution online as reference to other who might have the same problem. Here it is.
OS: windows 8.1 x64
I ran the vm with the VirtualBox and got this error:
init : cannot find ‘/system/bin/install-recovery.sh’ , disabling ‘flash_recovery’ IP Management : 192.168.56.101 failed to execute /sbin/v86d make sure that the v86d helper is installed and executable Getting VBE info block failed (eax=0x4f00,err=-2) vbe_init() failed with -22
I have tried
reinstall both genymotion and VirtualBox
upgrade and downgrade VirtualBox
Did not work.
After submited a ticket to genymotion team, I got a feedback:
Hello,
Running the VM from Virtualbox is not supported. You should use the “launchpad” that can be started by clicking on the Genymotion icon.
Regards,
Genymotion Support Team
Which provides no help. After a lot of google searches, I find a solution, it does not relate to Genymotion directly,
Uninstall one of the Windows 8 patches, KB3045999. This will affect to every user who is running virtual box under Win8.
If you have the same problem under windows as I did, please give it a shot.