App Crash restart

Source: Internet
Author: User

Test several app restart mode, or this way is more reliable;

public class APP extends application implements
thread.uncaughtexceptionhandler{
Context context;
Private Pendingintent Intent; After the app exits, Pendingintent still exists, and after 2 seconds of Setup, restart your main activity
@Override
public void OnCreate () {
Super.oncreate ();
context = this;
Set Thread Exception Handler
Thread.setdefaultuncaughtexceptionhandler (this);
Intent = pendingintent.getactivity (this, 0,new intent (this, mainactivity.class). Addflags (intent.flag_activity_ Single_top), 0);
}

@Override
public void uncaughtexception (thread thread, Throwable ex) {
LOG.E ("TAG", "uncaughtexception");
Alarmmanager mgr = (alarmmanager) getsystemservice (Context.alarm_service);
Mgr.set (ALARMMANAGER.RTC, System.currenttimemillis () +, intent);
System.exit (0);
}
Remember to register your appliction in manifest;
}

App Crash restart

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.