Issue
A = Main Activity
B = Some Activity
Normal case
A > B > Home Button > BApplication was killed case
A > B > Home Button > idle for some time > application killed > open app again > A
How can I do like case 2 ?
P.S. I tried to add android:launchMode="singleTask"
in Manifest. It always start at A but I would like to start at A in case 2 (application was killed) only.
Solution
Use this lines in your Application class. This code will automatically redirect your app to your desired page. if it get killed.
public class MYAppApplication extends Application {
Context context;
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
context=this;
MySafetyMethod();
}
private void MySafetyMethod() {
// TODO Auto-generated method stub
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
System.out.println("inside the process of handling exceptions");
System.err.println("inside the process of handling exceptions");
ex.printStackTrace();
System.exit(2);
startActivity(new Intent(context, YourActivity.class));
}
});
}
}
hope this helps you. and also dont forget to mention the application name in your manifest .
Answered By - itsrajesh4uguys
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.