Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android Apps
GitHub logo Twitter logo OReilly Book Cover Art
Rebooting the Device - The Hack WayBack to Android Cookbook Home | Up to Chapter: System and Device Control

Author: Saketkumar Srivastav ('Saket')
In Published Edition? No
FormatLanguage: WikiFormat

Rebooting the Device - The Hack Way


If you want to reboot an emulator, the hack way!


Android emulator makes a JNI reference to system server every time a Toast message is called upon. In emulator it takes about 20 seconds (on my emulator) to reboot an emulator which is approximately 2100 JNI references.


Simple code block that could reboot an emulator.

public class HackRebootActivity extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        while (true) {
        	Toast.makeText(HackRebootActivity.this, "", Toast.LENGTH_SHORT).show();

Whenever we invoke a Toast method the android system makes a weak JNI reference to the system server. The Toast method is enclosed in an infinite loop therefore the number of JNI references increases rapidly. Now as system server gets a lot of JNI references and therefore system server understands that this is something not desirable and hence system server crashes at around 2100 JNI references and reboots the emulator.

This is not an official way of rebooting a device but a hack way of rebooting. Here using this code a malicious coder could use this and reboot your device.

See Also

How to reboot the official (but usually disallowed) way