android collapses so we restart everyday - android

Guys I have an application that works on the tablet.That is a smart house application.I root the tablet because I want to forbid the customers to use anything else but application on the tablet.Application is always visible and working non stop on the screen whenever tablet is on.But there is a problem.The problem is when application running about 1 day sometimes 2 days tablet collapses.That's why it needs to be restarted each time when that happens.I think it might be a problem of ram aka main memory.I just wonder about your thought.If I use garbage collector or some ram cleaner or ram expander, will it be a solution for me ?
Thanks in advance.

Your problem appears to be a memory leak in your application.
Since this is a complex issue to identify and/or resolve, you could try some common tools to aid you, such as:
https://medium.com/freenet-engineering/memory-leaks-in-android-identify-treat-and-avoid-d0b1233acc8#.z178mon4s
http://android-developers.blogspot.ch/2009/01/avoiding-memory-leaks.html
https://github.com/square/leakcanary

Related

Android Program is running slow

I developed a firebase app, where one could post and you could like and react. Then, I stopped working on it. After some time, I started working on it again, when I was working on it, I found that the app now runs very slow, I had 3 layout (fragment used) and view pager added to it via adapter(before). Beforehand it used to work like a charm, but now when I move from one activity to other, the mobile device kind of like hangs. It was not behaving like this previously, why is that? Anyone facing similar problem?
First of all I would propose you allocate a larger memory to your ADB virtual device.
If this doesn't help, use Android Profiler to better understand the cause of this memory loss.
https://developer.android.com/studio/profile/android-profiler.html
Just go to your AVD device settings and disable Device frame, this will improve the speed of your emulator

Android 6: App uses more memory each time it's started

Samsung Galaxy S6 with Android 6.0.0 and 6.0.1
My app runs fine, code analysis shows no mem leaks. SmartManager shows that the app uses ~40MB of memory. I kill the app (using the "currently running apps" overview--- not sure how that's called in English, sorry. The key on the bottom left of the phone, that shows a list of miniatures of all running apps...), then start it again.
Now SmartManager no longer shows ~40MB of memory for my app, but ... more. 50. 100. 400. It varies, but growing each time. After awhile, my app actually crashes with an OutOfMemoryException. Sometimes even with "out-of-memory while trying to throw an OutOfMemoryException"...
I have to de-install and re-install the app in order to reset its memory consumption. The same APK behaves correctly on all other phones I've tested with (e.g. S5 with Android 5.0). No idea what's causing this. No idea what could be causing this! Any help/hints/suggestions...?
Edit: Same behaviour on S5 with Android 6.0.1, but not on S5 with Android 5.0!
Edit2: Thanks, everyone who contributed. I still don't have an answer that I'm satisfied with, but a few ideas were mentioned that I will look into. Most people were focusing on the MemLeak issue, and while that sounds reasonable I'd like to stress that there is no leak occuring on Android 4 or 5, only 6. (I have yet to test 7.) Also, the leak only occurs when I forcefully kill the app (which I need to do at times to test proper shutdown and re-start behaviour), and only without a debugger attached (which makes testing/debugging this behaviour a pain in the backside).
The app starts one service as a bound service. Bound to the application context--- which according to the docs should clean itself up when the app stops.
Unfortunetely, time for this bounty is running out. So far, the above mentioned service seems to be the most likely source of my problem. As such, I will award Qamar the bounty, as he was the first to mention this both in the comments and his answer. The rest of you, a big THANK YOU and up-vote.
In Android Studio, click Android Monitor at the bottom of your screen. Click the tab Monitors. You see a graph of the memory that your app uses. Now click the item Dump Java Heap which is next to the garbage van. The system starts collecting the info and creates a dump file. You can open the file in the Analyze Tasks tab in the upper right of your Android Studio window. Press the green arrow to find classes that leak memory. When you click a leaking activity, you'll see a window Reference Tree. Go through the tree, finding the member that has depth zero. That's the memory leak.
Analyse your code and images if anything wrong you are doing itself. Like very large images of drawables. make sure you correctly implement recycler or list views.
The following links may helpful to you.
Use leakcanary library to detect and make sure there is not leaks
Detect when user kill app from reccent apps
Invoke gc from memory monitor comes with Android Studio for correct value of memory usage cause gc not run frequently.
Use large heap size. <application android:largeHeap="true" in manifest
Use app context to start servicesstartService(new Intent(getApplicationContext(),MyService.class));
Your application has some threads are timer tasks that are creating again and again and they are utilizing many resources related to networks so your heap size is consistently increasing and at sometime your app is out of memory and crashes.
Some people think that task killers are important on Android. By closing apps running in the background, you’ll get improved performance and battery life – that’s the idea, anyway. In reality, task killers can reduce your performance.Android isn’t Windows and doesn’t manage processes like Windows does. Unlike on Windows, where there’s an obvious way to close applications, there’s no obvious way to “close” an Android application. This is by design and isn’t a problem.When you leave an Android app, going back to your home screen or switching to another app, the app stays “running” in the background. In most cases, the app will be paused in the background, taking up no CPU or network resources. Some apps will continue using CPU and network resources in the background, of course – for example, music players, file-downloading programs, or apps that sync in the background.When you go back to an app you were recently using, Android “unpauses” that app and you resume where you left off. This is fast because the app is still stored in your RAM and ready to be used again,hence consuming no further resources.
Task killers like smart manager think they know better than Android. They run in the background, automatically quitting apps and removing them from Android’s memory. They may also allow you to force-quit apps on your own, but you shouldn’t have to do this normally.If a task killer removes an app from your RAM and you open that app again, the app will be slower to load as Android is forced to load it from your device’s storage.Further s6 has Smart Manager and could be used as a widget or shortcut to battery and storage settings,however you should avoid using the Clean All optimization feature. This feature is said to improve device performance – as the Clean Master app aims to do – but its actual impact is questionable.
Meaning while still sometimes you kill an app it can still leave the traces on heap so next time when you start it ,it will show varyingly more amount of storage used which also fails the notion of default maxMemory() and the app ultimately might crash.Further such leaks are difficult to track as they aren't directly associated to app you killed in first instance.But still sometimes even after killing app, certain features like resources attained may keep running in background without even the app even knowing about them.i.e unnoticeable leaks.Thus you may want to use maxMemory()
which can be invoked (e.g., in your main activity's onCreate() method) as follows:
Runtime rt = Runtime.getRuntime();
long maxMemory = rt.maxMemory();
Log.v("onCreate", "maxMemory:" + Long.toString(maxMemory));
This method tells you how many total bytes of heap your app is allowed to use.
Optimal Behaviour:
An app can stay "running" in the background without any processes eating up your phone's resources. Android keeps the app in its memory so it launches more quickly and returns to its prior state. When your phone runs out of memory, Android will automatically start killing tasks on its own, starting with ones that you haven't used in awhile.
What You Should Do Instead
That said, not all apps are created equal. Many of you have used task killers in the past and actually found that after freeing up memory, your phone works a bit better. It's more likely that this is because you've killed a bad app that was poorly coded, and (for example) keeps trying to connect to the internet even when it shouldn't. Any performance increase you experience is more likely because you killed the right app, not because you freed up loads of memory (or, in many cases, it's just placebo). Instead of killing all those apps, find out which ones are actually causing the problems.using a task killer to deal with a misbehaving app is like using a shotgun to kill a fly – you may fix your problem, but you’re inflicting a lot of other damage in the process.Now
since S6 has 3 gigs of ram,it should'nt have problems,however implementation of smart manager can cause problems with some apps and isnt necessarily android version dependent.Also bare that heapsize tends to be based more on screen resolution, as higher-resolution screens tend to want to manipulate larger bitmaps.
Instead of using a task killer in this situation, you should identify the bad app and uninstall it,or debug it, replacing it with an app that works properly. To pin down the app that’s misbehaving, you can try the
Watchdog Task Manager app
– it will show you which apps are actually using CPU in the background, not which apps are harmlessly being stored in memory.
Captivating Fact:
CyanogenMod, the popular community-developed Android ROM, won’t even
accept bug reports from users using task killers, saying that they
cause more problems than they solve.
A probable cause of issue
if you can try following at once,first of all go to settings >sounds and notifications > App notifications > select smart manager and select hide content on lock screen
then again back to settings go to lockscreen and security >Device security >Disable KNOX active protection and deactivate the anti malware option below KNOX active protection
in lock screen and security go to other security settings > disable send security reports and go down to ussage data access> disable smart manager so after that restart your device.Now see if the app works Also see performace concerns with s6

Android screen stops reading inputs

First off, this has never happened before on any other android device I've used (multiple devices have been tried and tested before this).
Now I have an app that I have worked on for a little over a year now, it is called AutomatedId (on the app store) and it has worked quite well for my company for quite some time.
Recently I have been given a device to add compatibility to the app (specifically for reading UHF tags) but that isn't the problem.
The problem comes whenever you open the app, the screen stops reading inputs completely, as well as buttons cease to function. I turned on developer options to see the screen inputs and as i suspected, it completely stops and does not read any of the inputs after the app is opened. Clicks don't work, buttons don't work, keyboard doesn't open, hardware buttons on the device stop working. It's a mess, does anyone know what could have caused this?
This is a S98 from here: http://www.wepoy.com/product_view_18.html
moved my comment to the answer as you said. This may be due to memory leak. Here are some references that may help you fix them: Fixing-Memory-Leaks-in-Android-Studio & use this library from square to detect memory leaks early: leakcanary

Android App crashes on startup only on SGS2

I am having an app in the store which runs fine on most devices but on one particular
Samsung Galaxy S2 running Android 4.1.2 (version JZO54K.I9100XWLSS).
It crashes on startup without a crash-report from google or from crashlytics which i integrated. Its not actually a crash it just flashes the main activity a while until the phone shuts down:
A video of that behavior:
https://dl.dropboxusercontent.com/u/523370/20131004_115027%5B1%5D.mpeg
Its a device from a user, so I cannot debug it locally. (Is there something to get a live logcat stream from the phone over the air?)
Has anyone experienced such a "crash" on start only affecting one particular device?
I have a SGS2 where it works without flaws. Could there be any hardware reasons resulting in such a crash e.g. Memory issue.
I know this problem is not likely to be resolved without any further source code / crashreports, but maybe someone can point me in the right direction.
best regards,
Mike
Actually shoe rat saved my day!
Because shoe rat just commented on the case I am answering it for completeness.
The user enabled the option
"Do not keep activities" which lead to this strange behavior, because an activity was killed during the splash screen.
As a future reminder to myself I will get rid of the splash screen because its not holo-style anyway.
Cost me a lot of time to figure this out and i probably wouldn't have found it without your help.

Any way to speed up the Debugging of Android Application?

I'm building the android application but I'm fed up while I'm designing my app every time I change even font size I will have to wait for re-installation is there any way to speed up this designing way?
and also
if I change the code every time I'll have to debug is there any way to speed up this task too?
My main question is if I navigated to 10 Activity and the changes are in 11
then I'll have to re-navigate every time I would be hectic. I can not move directly to the 11th activity coz I need some values from the previous activity and one more thing
something like on-web page we do just refresh that particular page and see changes
##Note: This question will help you a lot with this problem see here
I have felt that debugging on device directly is faster than using emulators. Also, if you're working in windows, its a little slower than Linux and MacOS. You can try those platforms too
Sometimes, it is inevitable that you have to re-install the apk to test some changes. In order to speed this up, the only way will be to try to fine tune your system, so that it runs faster.
For testing a simple change, like a new font size, you don't have to reinstall the apk however. You can visualize the changes inside Eclipse or use a tool like DroidDraw.
Yes, there is a faster way though, first step run the debugger in Android Studio. The first thing you notice is debugger breakpoints might slow debugging dramatically(something like that). Then click on this ...
Here you can see all the breakpoints you have in your project.
You can remove debug points left in your project in the bottom box.
This boosted my debug process in any device this is the best solution.
kishu27 is correct by saying that debugging on a device is far quicker than using the emulator. If you don't have a device available, you can keep the emulator open between runs, so you don't have to wait for it to initialize each time (which really is painfully slow).
Another tip - if you have a lot of resources in the project that results in a large APK file, you could take out all the unnecessary ones while you're debugging a particular part of the application. This can speed up the installation process if the APK becomes a fair bit smaller. (This comes from experience when I was writing an app that had many sample videos in for testing - cutting out all but one and using that one wherever possible when it didn't matter what video was there meant the APK was far smaller and vastly sped up installation time.)

Categories

Resources