`
wcgdonot
  • 浏览: 92144 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

onCreate() | savedInstanceState()作用

阅读更多

在activity的生命周期中,只要离开了可见阶段,或者说失去了焦点,activity就很可能被KILL掉了,这个时候,就需要有种机制,能保存当时的状态,这就是savedInstanceState的作用。

当一个Activity在pause时,被kill之前,它可以调用onSaveInstanceState()来保存当前activity的状态信息(在paused状态时,要被kill的时候)。用来保存状态信息的Bundle会同时传给两个method,即onRestoreInstanceState() and onCreate().

分享到:
评论

相关推荐

    PinnedSectionListview

    protected void onCreate Bundle savedInstanceState { super onCreate savedInstanceState ; setContentView R layout activity main ; if savedInstanceState null { isFastScroll savedInstanceState ...

    savedInstanceState demo

    通过以上讲解,我们了解了`savedInstanceState`在Android开发中的重要作用,以及如何正确地使用它来保存和恢复应用状态。掌握这些知识,能帮助我们构建更健壮、用户体验更好的应用。在实际项目中,应根据具体需求...

    Android代码-CatLoadingView

    Android CatLoadingView This project idea is from Link. ...@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

    Android代码-一个简洁的基于 RxJava2 的事件总线库

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 注册 String 类型事件 RxBus.getDefault().subscribe(this, new ...

    Android 柱状图

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initData(); LinearLayout layout = (LinearLayout) findViewById...

    Android代码-RxBus2

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); RxBus.get().register(this); } public void test1005(View view){ ...

    yinyue.zip

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); TextView registerScreen = (TextView) findViewById(R.id.link_to_register); ...

    简易计算器

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { ...

    android时间控件

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initializeViews(); final Calendar c = Calendar.getInstance()...

    Android代码-YLListView仿IOS弹簧效果的ListView

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (YLListView) findViewById(R.id.listView); // 不添加也有...

    Android代码-安卓路由解决方案

    HippoRouter Android端URL路由解决方案... protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_example); initDataFromIntent(); } p

    一个封装WebView的库

    环境搭建新建一个activity继承WebActivity @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setWebChromeClient(new ChromeClient());//设置...

    android listview 上下滑动刷新

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pull_to_refresh); ((PullToRefreshListView) getListView()).setOnRefreshListener(new ...

    Android代码-Immersive

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Immersive.setContentView(this, R.layout.activity_main, R.color.blue, R.color.green, false, false); } } ...

    Android代码-简单实用的页面多状态布局(content,loading,empty,error)

    LoadingLayout 简单实用的页面多状态布局(content,...protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // ... vLoad

    Android ListView简单应用

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ArrayAdapter<String> arrayAdapter=new ArrayAdapter( MainActivity....

    Android代码-TouchRegion

    TouchRegion Scene View整体尺寸小,点击区域小,需要点击很多次才能选中; 通过设置View的padding属性增大... ... ... protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); set

    军棋安卓版源码

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // get handles to the LunarView from XML, and its LunarThread jqView = ...

    android开发示例

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Integer[] mButtonState = { R.drawable.defaultbutton, R.drawable.focusedpressed,...

    android mars视频代码 download源码

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button1 =(Button)findViewById(R.id.Button01); button2 =(Button)findViewById(R....

Global site tag (gtag.js) - Google Analytics