Android Security exits the application

Source: Internet
Author: User

  1. Kill the process. This method is ineffective and can only kill the currentActivityThe program cannot be closed, which is useful in 1.5. Google designed the program to prevent suicide.android.os.Process.killProcess(android.os.Process.myPid()).
  2. Terminating a running Java Virtual Machine causes program termination. This method is ineffective becauseAndroidYesdalvikVirtual MachineSystem.exit(0);
  3. Force disable all operations associated with the package. This method can only kill others and cannot kill yourself.
    Java ActivityManager manager = (ActivityManager) getSystemService (Context. ACTIVITY_SERVICE); manager. restartPackage (getPackageName (); permission application required

    Since the three methods described above have no effect, how can we exit the application?
    Is to customizeApplicationInApplicationDefineListTo record each EnabledActivityTo traverseListSet, and then proceed one by onemActivity.finish()Method.ActivityAre addedListInActivityWhen exitingListRemove it from the set.
    '''Java public class Activity01 extends Activity {

    @Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);    MyApp myApp = (MyApp) getApplication();    myApp.activies.add(this);}@Overrideprotected void onDestroy() {    super.onDestroy();    MyApp myApp = (MyApp) getApplication();    myApp.activies.remove(this);}public void click1(View view){    Intent intent = new Intent(this,Activity01.class);    startActivity(intent);}public void click2(View view){    Intent intent = new Intent(this,Activity02.class);    startActivity(intent);}public void exit(View view){    MyApp myApp = (MyApp) getApplication();     for(Activity ac : myApp.activies){         ac.finish();     }}

    }

    Public class Activity02 extends Activity {

    @Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.main2);    MyApp myApp = (MyApp) getApplication();    myApp.activies.add(this);}public void click1(View view) {    Intent intent = new Intent(this, Activity01.class);    startActivity(intent);}public void click2(View view) {    Intent intent = new Intent(this, Activity02.class);    startActivity(intent);}public void exit(View view) {    MyApp myApp = (MyApp) getApplication();    for (Activity ac : myApp.activies) {        ac.finish();    }}@Overrideprotected void onDestroy() {    super.onDestroy();    MyApp myApp = (MyApp) getApplication();    myApp.activies.remove(this);}

    }

    Public class MyApp extends Application {// stores all activity public List activies opened in the current Application; @ Override public void onCreate () {activies = new ArrayList (); super. onCreate ();}}

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.