0

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();
    }
}
Hoconosc
  • 416
  • 9
  • 24

2 Answers2

0

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

APZ
  • 176
  • 8
  • it doesn't turn screen on anymore – Hoconosc May 13 '12 at 17:06
  • Didnt you ask for **but the activity stays alive. If I use finish method, it doesn't get closed.** I answered that on how to close your activity. Maybe you can rephrase your question. – APZ May 13 '12 at 17:29
  • I did not -1 but yes, I want it to show activity before closing it, not closing it without showing anything – Hoconosc May 13 '12 at 17:30
  • Will the following help http://stackoverflow.com/questions/9561320/android-how-to-turn-screen-on-and-off-programmatically – APZ May 14 '12 at 16:10
0

Try to place your finish(); function in the

 @Override
public void onAttachedToWindow(){
    super.onAttachedToWindow();
    Log.d("MyLog", "InActivity->onAttachedToWindow");
    finish();
}
Evgeniy Mishustin
  • 3,343
  • 3
  • 42
  • 81