Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Android methods are called when battery dies?

When the battery on my Android device dies what methods in the Activity and Fragment classes (if any) are called during the "Powering Off" stage of the device?

Also, if a user is currently looking at a screen in my app and they hold the power button and choose switch off, do the events called/not called coincide with when the battery is depleted and shuts down automatically?

OnPause?

OnStop?

OnDestroy?

OnDetach?

Bonus: Will I have enough time to save a small amount of data to a web server?

To clarify "dies" when the device's battery is 'completely' dead, accepts no more input and a message box/loading screen pops up on the screen stating "Powering Off". Shortly there after the device switches off.

I just need enough time to save a forms state before the phone switches off, I have a strategy to clean the saved data should the phone not switch off, but I want to get as close to the phone switching off as possible (any more than a minute is pointless really).

like image 340
Smithy Avatar asked Jan 08 '15 17:01

Smithy


People also ask

When onStop method is called in Android?

OnStop is called when FirstActivity calls SecondActivity and FirstActivity looses visibility. If Second Activity has a transparent background then the FirstActivity will be visible underneath, so not loosing visibility and onStop on FirstActivity will never be called.

What are the life cycle methods of Android activity?

An Android activity goes through six major lifecycle stages or callbacks. These are: onCreate() , onStart() , onResume() , onPause() , onStop() , and onDestroy() . The system invokes each of these callbacks as an activity enters a new state.

What are the activity states in Android?

Hence, all in all there are four states of an Activity(App) in Android namely, Active , Paused , Stopped and Destroyed .

What is called when the activity is no longer visible to the user?

If the activity stops being visible to the user, the onStop() method gets called. After the onStop() method has run, the activity is no longer visible. If the activity becomes visible to the user again, the onRestart() method gets called, followed by onStart() and onResume().

Why does my phone battery just die?

The battery doesn’t ‘just’ die. It will either die from degeneration, or if it has been damaged, such as water. If your phone has a removable battery, it’s easier to replace the faulty battery. If it is non-removable, you’d have to go to a specialist to replace it for you, as it can be potentially dangerous.

How to fix Android system battery drains?

Part 1. One Click to Fix Android System Battery Drains If you do not wish to go into the methods that fix a small thing here and there, you may use a dedicated repair software to fix the entire operating system of your device. Fixing the core system will fix all other issues including the battery drain issue on your device.

Which processes use the most battery on a smartphone?

No single process uses a ton of battery most of the time. It’s the fact that your phone probably has dozens of these background processes running at once that causes problems. Background tasks and processes aren't nearly the problem they once were thanks to Doze Mode and Adaptive Battery.

How does a phone’s display affect battery life?

The second way a phone’s display affects battery life is the resolution. Admittedly, the differences aren’t huge, but it is objectively measurable. Displays with 1440p resolution have 77% more pixels than a 1080p display and it requires extra processing power (and therefore, more battery) to render those extra pixels.


1 Answers

onDestroy is called on everything when the battery reaches 0.5%

EDIT: There is no specified time that you have to do anything in the shutdown process resulting from low/dead battery, that would be dependent on the specific phone battery and not the system, so you may have enough time to save data to a web server on some phones but not others. Experimentally, I have only been able to write a short line to a file I was already writing to before onDestroy was called and nothing more.

like image 119
John Avatar answered Oct 04 '22 21:10

John