简体   繁体   中英

Finish empty activity

I'm trying to turn screen on using an activity. I reached my goal, but the activity stays alive. If I use finish method, it doesn't get closed.

Note: it doesn't work even if I setContentView(...my xml...);

package it.android.smartscreenon;

import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;

public class AccendiSchermo extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
                finish();
    }
}

Try System.exit(0); in place of finish();

Try to place your finish(); function in the

 @Override
public void onAttachedToWindow(){
    super.onAttachedToWindow();
    Log.d("MyLog", "InActivity->onAttachedToWindow");
    finish();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM