The best practice for app launch time duration Android - android

I need to measure the App Launch time. What I am thinking of is to have a static variable of the current time on Application onCreate and in the 1st fragment of the app I subtract this variable onActivityCreated. But I do not think this is the best practice. Is there a lib or a call that provide such result?. Appreciated your kind help.

You can use a tool such as TraceView to help debug the application and profile the performance. It's basically a a graphical viewer for your execution logs.
To start the Traceview tool:
Start the Android Device Monitor.
In the Android Device Monitor tool bar, click DDMS and select a process.
Click the Start Method Profiling icon to start method profiling.
After the profiling is complete, click the Stop Method Profiling icon to display the traceview.
There is more information on how to use TraceView here:
http://developer.android.com/tools/debugging/debugging-tracing.html

Related

Simple android application to prevent the use of camera

As the title stated, I want to design simple application without interaction from the user. After installation it will block the camera. then start a timer to release it after some time.
I tried 2 options: device manager using set camera disabled method but I could not run the project because of some errors in the manifast.
now I'm trying just to create a camera object to reserve the camera from other applications. but still the native camera app was able to start the camera.
My question: is my method correct? or there are much simpler ways to do it.
device manager using set camera disabled method but I could not run the project because of some errors in the manifast.
Perhaps you should consider asking a separate Stack Overflow question where you explain what you tried and what specific problems you encountered. If by "device manager" you mean the device administration APIs, this is the proper way of implementing what you want.
is my method correct?
No.

How can I programatically take a screenshot of the entire app?

I'm working on UI automation tests for an Android app. I need to save off a screenshot of the app as it appears during various steps of the test for later analysis by test engineers.
The usual way to do this in Android is to get the Window, then get the DecorView, then call onDraw with a Canvas backed by a Bitmap and save the Bitmap. This doesn't work when a Dialog is showing on top of an Activity, however. The Dialog and Activity each have their own separate DecorView.
Is there any way to programatically take a screenshot of the entire app with all windows composited? Unfortunately, the device is not rooted and the app does not have signature permissions, so this answer in another thread does not apply:
https://stackoverflow.com/a/13837910/244521
For phone devices: This article shares some tips that might help. However, on ICS and above, you may need to use Home + Power, not Volume Down + Power, as the article says.
For automated tests, perhaps AutomatedScreenshots will help

Intentionally have the system close and restart app

I have been seeing errors come back from my application that it's force closing after the system stop's it and the user bring it back to the front at a later time.
I have some idea's as to what is causing this but I would like to be able to reproduce this error before attempting to fix it.
Does anyone know a way to get the android system to behave like it needs the memory my application is using and close it so I can easily and continually reproduce this error?
Using the Dev Tools app on your emulator, you can have the OS destroy an application as soon as it's stopped.
From the documentation:
Immediately destroy activities
Tells the system to destroy an activity as soon as it is stopped (as if Android had to reclaim memory). This is very useful for
testing the onSaveInstanceState(Bundle) / onCreate(android.os.Bundle)
code path, which would otherwise be difficult to force. Choosing this
option will probably reveal a number of problems in your application
due to not saving state. For more information about saving an
activity's state, see the Activities document.
You can find this under Development Settings once you're in the Dev Tools app. So, when running your application, you could just switch to another application (like clicking on the emulator's hard phone button), and return to yours to test the destroy/create process.
If you are using Eclipse or DDMS you can select your app in the process list and hit the stop button. This should close your app.

no rendering time info in android hierarchyviewer

Hi, I try to follow android's Debugging and Profilling UI article and started the hierarchyviewer.
I am following the steps in the tutorial:
start emulator
start app
open cmd and start hierarchyviewer
select my activity and wait. The application is the spinner sample from SDK samples.
However, all rendering time related info are n/a, no measure time, no layoutime, no drawtime, no color circles, as show in the screen shot.
I also tried to exit eclipse because some info said debugger may causing problem but nothing changed.
am I missing any thing?
Thanks
Apparently, this only works from Android 2.3 onwards
(see https://groups.google.com/group/android-developers/tree/browse_frm/thread/b8aac9fe39ec1941)

How to stop a program running under Eclipse?

I can't find an option to stop a running program (whether in debug or release mode).
So for now, I stop the program (returning control to Eclipse) simply by closing the emulator.
Is there a better way of doing this? Such that I don't need to close (and restart) the emulator?
I understand you want to stop your app on the emulator. For this you can open up the devices window (in the debug perspective), select the process and then press the stop button on the same window.
Those who find it tedious switching between perspectives to stop the program (like I did), you can view the devices windows in your current perspective by selecting
Windows > Show View > Other... > Android > Devices
Keep in mind that on Android, programs generally only 'stop' if you finish() or the system destroys them when memory is required. Why stop at all? You do not need to stop to fix/re-install/re-test, for example.
In the "Debug" perspective, select the root of the application under "Debug" (where the listing of active threads is) and click the stop button.
Working for me.
Windows -> Open perspective -> Other... -> DDMS
In the Android view, on the left windows, you can see "Devices". There should be a list of applications that is running now (Emulator or physical devices).
Click on the application you want to close. Normally the name is the name of the package + the name of the application
Now click on the symbol of "Stop".
To come back to the normal view, you just have to press on the Java button on the top right side.
You can also do it pressing:
Windows -> Open perspective -> Other... -> Java
this answer doesn't deal with Eclipse, but since this question comes up in a Google search for stopping a running Android program, I'd like to offer a command-line method. run adb shell, find the PID of the process you want to kill with ps, for example mine was:
u0_a46 2097 37 175520 19912 ffffffff 40037ebc S net.unternet.bleah.blarg
so then just kill 2097 and you should see the main screen show up again.
Add breakpoint to your code where you want to stop and then run it in Debug mode by pressing F11.
Figure 1 - Many Zombies were killed during the research of this Answer
Killing an Android application Java VM process at the OS level is not recommended. Unfortunately, this is exactly what the eclipse device window "stop" does, as does System.exit() and the shell "kill" command.
This subverts the normal app life-cycle methods such as onStop(), onDestroy(), and finalize().
Many apps require these methods for graceful exit (for ex. if they use system objects like Sensor, MediaPlayer, Equalizer, Visualizer, etc).
These system objects hang around with zombie death grips on system resources if release() is not called explicitly during these life-cycle methods. See fig. 1 above. This can prevent an app from restarting, and even require a reboot. That is the ungraceful aspect.
The only solution is to make sure you always exit your app cleanly with a call to onStop() or onDestroy() or at least finalize(). The debugger does this, as does the OS on shutdown.
You can set your app to trap SIG_HUP events in order to force a graceful exit from the command line.
The only time you would kill the app VM is in ANR (already a zombie) state. ANRs must be fixed. Never deploy an app that can enter this state. It is extremely rude.
You can use Google analytics and the Play Store to monitor for these in deployment. You don't want angry users giving single star ANR reviews after having to reboot due to your zombie application. Very bad.
Remember that Android is Linux: treat it like a real OS, and respect the app life-cycle otherwise you shall surely face the dreaded Zombie Apocalypse.
PS: If you don't like the Zombie analogy, how about Fantasia?
See picture:
1. Click on DDMS;
2. Select current app;
3. Click on "Stop"

Categories

Resources