StartActivity Performance - android

My app started to get really slow between activities and I started to investigate
from the time I run StartActivty until onCreate in that activity start, can take up to 1000ms
Can anyone tell me what this could be
I tried to remove everything in oncreate and it's not it.. it's simply the 800ms to 1000ms before it even runs onCreate

The reason could be hidden in your xml layout files. Xml parsing itself is resource consuming. So check them out.

If you are running the application in 4.x device. Please the Setting -> Developer Option-> Don't Keep Activites enabled or not.
If it's enabled your application might be slow.
Please check out the option.

Related

Why My Phone hangs up after app is crashing which I am working on?

Working on a app which contains a lot of data in the home page like lot of gif images ,maps ,videos and many other things.
The real problem is my app now hangs up almost in every device after app is crashed and then I need to restart device. It's a weird behavior as I don't get any error or exception in the logcat.
How could I resolve the root cause. I have even tried to put less load on main thread but still problem is there.
I have used Services in the app to fetch the data from the server in the background without interrupting user. Is this may the cause ?
Not a lot of help can be offered based on your question.
Possible debugging technique:
Use Try catch block, and check for exceptions.
Use built in debugger in Android Studio, for step by step traversal.
If you are getting information from web, try doing it in background threads.

How to solve application stopped work bug?

My application is probably running out of memory or it is some issue with that. I have exception handling on application so if i got exception It is send to my email, it is good for debug, but recently I have got a strange issue, when I put my application to background and start 2-3 other application for example Gallery when i want to reopen my application instance it shows me Application stops work and no exception is send to me, so it is hard to solve, can you please help me to solve my issue, or handle that memory issue and restart the whole app instead of showing that the application has stopped worked.
thank you very much. It will also help if you show me how to simulate that memory issue when the application is in debug mode.
my manifest:
<application
android:name=".utils.JLApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="JustLook"
android:largeHeap="true"
android:noHistory="true"
android:launchMode = "singleTop"
android:theme="#style/JLTheme">
I also think that maybe my application is correct but some of the libraries or something has stopped to work and that throws my application. But I am not sure of that. I also noticed that it happened frequently when i implemented google api connection and fuse location listener, but i am also not sure if it causes this kind of problem, maybe the memory issue is more likely bug here. But I dont know how to find it or solve it because it does not throws exception.
I dont think that your problem is memory related.
According to how you describe your problem, i'm assuming that your crash is caused by a NullPointerException.
As MarkySmarky described, Android kills background applikations to gather memory space.
So please have a look at your MainActivitys onResume or onStart. There must be some handlers, adapters, etc. that are null when you are resuming your app.
In addition, i would suggest to add Crashlytics to your project. It tracks your crashes in detail. If have a crash report regarding your problem, please post it here.
I must say that the behaviour that you've described sounds perfectly normal besides that crash thing ;)
Android kills background applications when it needs to free up memory for other apps. The crash you're having MUST somehow be related to your code running in onCreate() of JLApplication. The best way to debug or find this bug is either start your application in debug mode or spread logs all around.
You can also take a look at Debug.waitForDebugger().
btw you should have a really good reason for having the following in you application tag - "largeHeap"

how to figure out the flow of an android project using debug

I'm new to android development.
I download a toy project and want to figure out the flow of this project.
Can I use debugging to figure out it and how?
Let me explain it more detail. Every android project starts from an "main" activity. I guess I find the "main" activity for the project and set a breakpoint at the onCreate method of this "main" activity. I expect to run this project from that breakpoint one step by step to figure out the flow. However it doesn't work since the debugging stop after finishing the onCreate method.
Start with AndroidManifest.xml file. Open it and look for an Activity with LAUNCHER category. Then open that Activity and go to onCreate(...) method. This is where your app starts. Inside the method, there is a call to setContentView(R.layout.some_layout). some_layout.xml in res/layout folder is UI for this Activity.
Each window you see in Android app is an Activity and each Activity has a layout file.
The "flow" of an android application is more like an asynchronous model than a sequential flow of action. There is a main application loop that processes external events (such as clicks on button) and callbacks related to the activity lifecycle (such as your onCreate method), and lot of other stuff.
Every event is put into the queue and processed asynchronously, so it's not easy to follow it. It's better to think about actions and reactions. In any case you can dig into the android source code and see what's running behind the scenes. Some hints about the model of android apps can be found here but any google search for "android ui thread queue" would lead to relevant info.
If you want to learn the flow of a typical android application, I would recommend you download the samples if you haven't already and add your own log statements. You could use the debugger too. Then start making small changes here and there to force different 'flows' of control, as you make guesses about what should happen and observe your logging statements and the app behavior to see what's going on.
The sample projects can be downloaded from the adt plugin in eclipse and come as ready-made projects. They are also a good way to learn because they are generally the 'best-practice' way of doing things.
Hope that helps! Good luck :)

How to avoid "Activity not started, its current task has been brought to the front " warning?

If I don't modify source code and compile, I get "Activity not started, its current task has been brought to the front" message. Is there option in Eclipse to force it to run without changing source code?
If u want to enforce it do this.
I do this usually though it sounds lame. Add a space anywhere in your code (in any file). Just Save the project and run. It will then go through the uploading and installing process again. This is the easiest way to go about it without actually changing any code that matters.
why dont u try running it from Emulator again, If you are not modifying source, it will do the same as you mentioned, Either change source(you can add logs, or just do blank enter in any file.) or close it and open it from Emulator.
-->This happens only if there is no change from the previous run of your Application.
-->To Avoid this , You can either::
Close your Application and then Compile,
You have to change atleast 1 file of you code and then can Compile it.
There is another way to solve this problem. Run the another app and than run your current app, so you not get this type of error message. And not needed to change the code or adding unnecessary spaces. and it also save your time which can waste to restart the emulator.
If u dont modify the code and want to re-run the code in emulator,the system just throws the warning that the code you are trying to run is already executed.Even i have faced this warning several times.You can do is make some changes in code and try to run again or just finish up all the activities in front and than try to run.It will run successfully.
In my opinion 'Activity not started, its current task...' is really tedious. In some cases I changed nothing in source code, but need to restart because I changed the data
Clean your project(Menu->Project->Clean) then Run it again.
Works for me.

Avoid reloading activity with asynctask on orientation change in android

How do I avoid reloading the activity with asynctask class in activity when the user changes orientation, in android? Can anybody give an example?
Please turn off config changes as a last resort. Your app must work correctly when this happens. If you turn off the orientation config change because it breaks, your app will still break in other and some times more subtle way. Allowing the activity to be restarted due to an orientation config change is a very good way to easily test these important code paths of your app that are otherwise much less often exercised but still will result in failures in your users' hands.
To transfer active objects across Activity instances, use the new fragment static library which allows you to make a fragment that is retained for you across instances.
Chirag have already correctly pointed out the solution.
I just want to add that, restart of Activity has nothing to do with the AsyncTask in it. By default, when there are any config changes,the activity is restarted UNLESS the config change is explicitly handled by the Activity. This is done by making an entry in manifest file.
Go through this link developer guide : android:configChanges
NOTE: Check the code on a device not on emulator. Because I had faced similar problem earlier. The same code didn't worked on emulator but it worked on device perfectly. So add the entry for android:configChanges in manifest and check the application on a android device instead of emulator.
And I second #hackbod. Do it only if necessary!

Categories

Resources