2015-05-07 29 views
-3

我正在製作一個android應用程序,其中在方向更改時必須保存一些變量。我怎樣才能做到這一點 ?如何在方向更改時保存變量

,如:boolean p;

+0

http://developer.android.com/guide /topics/resources/runtime-changes.html – CommonsWare

+0

使用'onSaveInstanceState()'和'onRestoreInstanceState()'。 –

回答

0

在onCreate方法

if(savedInstanceState!=null) 
{ 
p= savedInstanceState.getBoolean("flagp"); 
} 

添加這個和這個在活動課

@Override 
protected void onSaveInstanceState(Bundle outState) 
{ 
outState.putBoolean("flagp",p); 
} 
相關問題