Activity Notes

本文探讨了Android应用中因未正确声明MAIN行动或LAUNCHER类别导致应用图标不显示的问题,并提供了代码示例来解决该问题。此外,还介绍了如何通过onSaveInstanceState和onRestoreInstanceState方法保存和恢复游戏状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

If either the MAIN action or LAUNCHER category are not declared for one of your activities, then your app icon will not appear in the Home screen's list of apps.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    // For the main activity, make sure the app icon in the action bar
    // does not behave as a button
    ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    // Save the user's current game state
    savedInstanceState.putInt(STATE_SCORE, mCurrentScore);
    savedInstanceState.putInt(STATE_LEVEL, mCurrentLevel);
    
    // Always call the superclass so it can save the view hierarchy state
    super.onSaveInstanceState(savedInstanceState);
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public void onRestoreInstanceState(Bundle savedInstanceState) {
    // Always call the superclass so it can restore the view hierarchy
    super.onRestoreInstanceState(savedInstanceState);
   
    // Restore state members from saved instance
    mCurrentScore = savedInstanceState.getInt(STATE_SCORE);
    mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL);
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值