覆盖android中的空闲超时

1 android

我正在构建一个应用程序,我想覆盖应用程序的空闲超时.我希望它永远不会超时,类似于大多数游戏.有谁知道你是怎么做到的.我一直在互联网上拖了一会儿,我不确定.

iPhone是idleTimeout = NO;

超级简单,有没有像我可以在Android中看到的全局设置?我没有在Android开发人员或我看过的任何网页上看到任何内容.

万分感谢!

我有第二个背驮式问题.我也有内存泄漏.这是代码[code]包fourguys.testing.IntentTest;

import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.media.MediaPlayer; import android.media.AudioManager; import android.content.Context;

公共类CanvasDrawingActivity扩展Activity {

private static final int FIRE = 0;
private int initVolume = 0;
private Handler handler;
private MyCanvas v;
private MediaPlayer mp;
private AudioManager am;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    am = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);

        // this method gets the current volume setting for music
        initVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);


        am.setStreamVolume(AudioManager.STREAM_MUSIC,100,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);

    mp = MediaPlayer.create(this, R.raw.test);

    makeHandler();
    v =new MyCanvas(this);
    new Thread(new Runnable(){
        @Override
        public void run() {
            while(true)
                handler.sendEmptyMessage(FIRE); 
        }}).start();
    setContentView(v);
    mp.setLooping(true);
    mp.start();
}
private void makeHandler()
{
    handler  = new Handler(){

        @Override
        public void handleMessage(Message msg) {
            switch(msg.what)
            {
            case FIRE:
            {
                v.invalidate();
                break;
            }
            }
        }

    };
}
protected void onPause() {
    super.onPause();
    mp.stop();
}
protected void onFinish() {
    mp.stop();
}

}
Run Code Online (Sandbox Code Playgroud)

[/码]

还有这个:

[code] package fourguys.testing.IntentTest;

import android.app.Activity; import android.content.Intent; import android.media.MediaPlayer; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.view.WindowManager;

公共类IntentTest扩展Activity {/**首次创建活动时调用.*/

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    //reciever intentReceiver = new reciever();

   // IntentFilter intentFilter = new IntentFilter("com.app.REC");

    //registerReceiver(intentReceiver, intentFilter); 
    Button b = (Button)this.findViewById(R.id.endButton);
    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(IntentTest.this,CanvasDrawingActivity.class);
            startActivity(i);

        }
     });
 }
// the onPause method get called when the app is either being hidden or being closed so this the place where we would want to clean anything up like stoping the media player.
@Override
protected void onPause()
{
    super.onPause();
}
}
Run Code Online (Sandbox Code Playgroud)

[/码]

我运行应用程序,退出时会变得很糟糕.它会锁定听筒并导致电池发热.我需要物理拉电池才能重启.有什么想法可能是什么?它在模拟器上运行得非常漂亮.我应该使用onFinish,还是我不清理某些东西而我却想念它?

ada*_*amp 6

不要使用唤醒锁定,而是将窗口设置为在显示时保持屏幕开启.系统将负责细节.来自您的活动:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Run Code Online (Sandbox Code Playgroud)