【问题标题】:Any idead how to pause~resume/stop~restart the application? Disable auto lockscreen?知道如何暂停~恢复/停止~重新启动应用程序吗?禁用自动锁屏?
【发布时间】:2015-09-08 07:25:59
【问题描述】:

当我最小化时,对象的分数和位置等数据会被重置。当我锁定屏幕时,应用程序会重新启动。有没有办法保存所有对象数据以使其恢复后的位置和分数相同?以及如何使块屏按钮(与等待锁屏相同)不会使应用重新启动。是否可以通过应用程序禁用自动锁屏?

抱歉,问的太多了,我是新来的,在其他问题中找不到我想要的。

这是我的 Activity 类:

`public class Home 扩展Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(new GamePanel(this));//GamePanel is the SurfaceView


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_home, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}`

【问题讨论】:

    标签: android android-activity surfaceview onresume onpause


    【解决方案1】:

    我认为你应该使用 saveInstanceState 和 restoreInstanceState。

    http://developer.android.com/training/basics/activity-lifecycle/recreating.html#SaveState查看“保存您的活动状态”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-07
      • 2013-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-23
      相关资源
      最近更新 更多