GithubHelp home page GithubHelp logo

Comments (2)

904079904 avatar 904079904 commented on June 30, 2024

have you declared this activity in your AndroidManifest.xml? 如果 配置了 再次亮屏幕就是黑色的

from android-keeplive.

gaoyuyu avatar gaoyuyu commented on June 30, 2024

have you declared this activity in your AndroidManifest.xml? 如果 配置了 再次亮屏幕就是黑色的

我调试过,KeepLiveManager.getInstance().setKeepLiveActivity(this); 这句是执行了,但是get到的PixelActivity是null,我改成用广播的方式了,暂未发现问题

Log.i(TAG, "发送finish广播,结束流氓Activity");
getApplicationContext().sendBroadcast(new Intent("finish_Activity"));

public class PixelActivity extends AppCompatActivity
{
private final static String TAG = PixelActivity.class.getSimpleName();
private BroadcastReceiver endReceiver;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    Logger.d(TAG, "PixelActivity -> onCreate");

    Window window = getWindow();
    window.setGravity(Gravity.LEFT | Gravity.TOP);
    WindowManager.LayoutParams params = window.getAttributes();
    params.x = 0;
    params.y = 0;
    params.height = 1;
    params.width = 1;
    window.setAttributes(params);

    //结束该页面的广播
    endReceiver = new BroadcastReceiver()
    {
        @Override
        public void onReceive(Context context, Intent intent)
        {
            Logger.d(TAG, "接受到finish的广播");
            finish();
        }
    };
    registerReceiver(endReceiver, new IntentFilter("finish_Activity"));
    //检查屏幕状态
    checkScreen();
}

@Override
protected void onResume()
{
    super.onResume();
    Logger.d(TAG, "PixelActivity -> onResume");
    checkScreen();
}

@Override
protected void onRestart()
{
    super.onRestart();
    Logger.d(TAG, "PixelActivity -> onRestart");
}

@Override
protected void onDestroy()
{
    super.onDestroy();
    Logger.d(TAG, "PixelActivity -> onDestroy");
    if (endReceiver != null)
        unregisterReceiver(endReceiver);

}

/**
 * 检查屏幕状态  isScreenOn为true  屏幕“亮”结束该Activity
 */
private void checkScreen()
{
    PowerManager pm = (PowerManager) PixelActivity.this.getSystemService(Context.POWER_SERVICE);
    if (pm != null)
    {
        boolean isScreenOn = pm.isScreenOn();
        Logger.d(TAG, "PixelActivity isScreenOn->" + isScreenOn);
        if (isScreenOn)
        {
            finish();
        }
    }

}

}

from android-keeplive.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.