I want to know the average start-up time of all the apps on android device. And this is supposed to be done by my app. So, is it possible to get such information from the app level programatically?
I assume you mean the time it takes for a given app to complete its onCreate() method. You might be able to do something on a rooted phone with extending onCreate() with a timer that logs to somewhere for your app.
This isn't going to work. You would have to start an app and time it, but you do not have access to the information about when another app has finished loading. Furthermore,.. how do you define start-up time? The time taken until the app opens or the time until past the loading screen.. or the time until past the splash screen...?
The way I am trying to solve this problem is by using a service to monitor the logs that will start a timer when app X is started. We have that working properly. The problem we are having is how to define the app as done loading. Once we have that we can gather data. But I am still looking for a way to know when app X moves from the onCreate() method from one activity to the onCreate() method of another. This will obviously only work for apps that have a loading activity for their app.
Effectively, this a really hard problem to both define and solve. If you ever come up with anything different than what I have, I'd love to hear it.
Related
So, for my Android course this semester we're making an app of our own choosing, and due to a lack of ideas I decided to go with a text-adventure styled game. Nothing too complicated, I know. I'm making sure to be creative and incorporate a lot of different functions of the phone, such as the accelerometer and the camera. But I digress.
I've started planning out how the app should work, and how I should go about coding it, but I've come upon an obstacle fairly early that I need to find a solution for. I'm planning on creating it so that the player is sent from activity to activity, which I think is the best way to go about it, unless I do an endlessly scrolling activity that fills out as the player progresses. And thus, I need a way to make it so that when the player closes the app completely it will "continue" on the last activity before shutdown, so the progress is saved in a way.
I'm not sure if this is possible to do, and if so, are there any other ways I can achieve the same sort of result?
There is no way that you can change your starting activity programmatically. You can save the activity that you want to start with in a file and redirect to this activity from your main activity every time your application starts (on the onCreate() method of your main activity).
As it says here.
As someone has suggested, save the current state (ie: what Activity is currently shown) in SharedPreferences. When the user launches your app, the root Activity (the one with ACTION=MAIN and CATEGORY=LAUNCHER) will be started. In onCreate() of the root Activity, read the saved state from the SharedPreferences and launch that Activity immediately.
I'm developing an application in cordova/phonegap and it is about tracking a person his gps location and therefore the app needs to be active for a long time
I can keep the application active as long as it is in memory but when you have opened so many applications that android needs more ram space it still kills the application
I know services exist in android but I just cant tell how to use them in combination with a phonegap app
Is there a way to keep the activity of my app in front of the activity stack so it doesnt get killed or can i write a native service that restarts my application when it gets killed (with thesame state as it got when it got killed)
More detailed description of the problem
ok as requested a more detailed description of the problem
I have a cordova application (html + javascripts)
in a the application i use navigator.watchposition() which gets called when the gps location changes
i then do some logic and store the data in a websql database (on the device itself), as far as i know this database is only accesible from within a webview
now the point of this application is that it you start it at the morning and stop it in the evening (for example lets say say active for 10 hours from start to finish) you dont need to see the application, and the screen doesnt need to be on
I got the stay active part working for when android never ran out of memory
So what I need to do to get to my problem is start the application -> press the home button -> start about 10 different application (to simulate normal use of a phone), the number 10 can vary on different phones with different ram sizes -> after opening enough other applications my phone will run out of ram memory so then android kills some apps and eventually will kill my app.
This is not good for our application at it tracks time at a location and needs to do this fairly accurately
-------
anyway thanks in advance for your help
You should not try to do that. It's against the principles of Android. Instead you should, as you already suggested yourself, use a service to track the GPS location.
I have met the same problem.
In android, activity life cycle can only changed by system, when the activity not on the top, it will easy to be killed by system, so next time you come into your app , it will start from onCreate function on main.java.
If you want make something work background , use service will more appropriate.
I'm trying to create a monitor service which would know when apps start/resume/restart/pause/... and also when apps crashes.
I have tried to read logcat, but it seems that calls to [onCreate()/onStart()/onRestart()/...] are not logged into logcat.
Is there a way to catch all these method calls for all running apps ? Is there a way to know when an app crash ?
Note: The service don't need to be notified as soon as these events happens, few seconds/minutes after is also okay.
Refer to my code in this answer:
Android how to know an app has been started and range apps priority according the starting times
You can monitor it as follows:
If an app is in the foreground, that is if it is in start, then it will be the first item of the List taskInfo.
If it is paused, it will no longer be the first item in that list.
To check resume, see if it previously was not the first item, but , in the current iteration, it is the first item.
I am not too sure about the crash part, but maybe you can find a similar way from the above logic.
You can check out Crashlytics for crash tracking. You can see crashed lines in methods as well.
I know how Android works concerning killing not needed processes if the memory is needed by another app, bu I dont like the following behaviour of the App I develop at the moment:
I start my App, which has a lot of different screens/activities
After using it, i push the Home Button of my phone and switch to some other App.
(Lets say I did this while Activity C on Screen C was active).
My phone is a HTC One X, I checked, that there are always about 300MB of Memory available, when I run the Apps I usually need.
The Problem:
Even if I restart the App after a couple of days without using it, the App restarts with Activity C on screen C. In my opinion, after some days of not using the App, it should restart with the "Welcome Screen" i created.
As there are no Backgroundprocesses or ressources used (all these stuff is done by pushing buttons and has to be finished - so no automated backgroundprocesses are needed), I think, Android does not feel the need to kill it.
Does anybody know, how the "Android Best Practice" looks like for this or where I can read what behaviour the App should have in this case?
(... I am not looking for Code, but I dont know what way I should go to solve this)
Many Thanks for any help
I think you can easily do finish() the activity's on onPause() method.
Not sure whether this is a best practice. Awaiting other answers.
If I'm not mistaking, the following flag can help you when used by an Intent starting a new Activity: FLAG_ACTIVITY_NO_HISTORY. As the documentation says:
f set, the new activity is not kept in the history stack. As soon as the user navigates away from it, the activity is finished.
So if all your Activities, except of the welcome screen, are started using this flag, next time a user comes back to your app he arrives at the welcome screen. The drawback of this solution is that if a user receives a call while working with your application, he will also be transfered to welcome screen when the call is finished. Don't know if there is any other solution. Hope this helps.
I am doing an application in android which requires to know for how long the application is running. Do anyone know how to retrieve such information??. Is there any way where android provides the information about the running applications ,from how much time they are running??
I'm not aware of any method which would handle that but you can simply implement it yourself. Just capture the current time in seconds and in the onPause() method do the same. Then just subtract the first saved time value and the last saved value and you should know for how many seconds the application was running.
There might be another more elegant solution I don't know of tho.
You could user SystemClock.uptimeMillis() or SystemClock.elapsedRealtime() in your main activity once it is first launched. Then each time you need to see how long the app is running call the method again and subtract from the original value.
There is some data collected for all applications to show battery usage by application, but I've not done the research to find out how to access it programmatically (if even possible) and am not sure when it is reset (perhaps on every charger/usb disconnect).
For one application the previous suggestions about instrumenting create and pause/resume methods sounds best.