標籤:for stop 布局檔案 str instance led onrestart 使用 long
1.從看得見的活動入手
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //調用了父類的onCreate()方法。
setContentView(R.layout.aty_timeline); //設定布局檔案。
}
隱藏標題列:requestWindowFeature(Window.FEATURE_NO_TITLE),放在setContentView(R.layout.aty_timeline)的前面。
2.布局檔案
3.Toast的使用
Toast.makeText(FirstActivity.this,R.string.abc,Toast.LENGTH_LONG).show();
4.銷毀活動,一句話。
finish();
5.Intent的用法。
顯示+隱式
顯示:
Intent i = new Intent(AtyLogin.this,AtyTimeline.class);
i.putExtra(Config.KEY_TOKEN,token);
startActivity(i);
擷取Intent傳的值:
Intent data = getIntent();
msg = data.getStringExtra(Config.KEY_MSG);
隱式:設定檔中添加category,自己查書瞭解。
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.baidu.com"));
startActivity(intent);
6.傳遞與返回資料:
傳送:
Intent intent = new Intent(AtyLogin.this,AtyTimeline.class);
startActivityForResult(intent,1);
接收:
Intent intent = new Intent();
intent.putExtra("data_return","Hello!");
setResult(RESULT_OK,intent);
此方法非常重要,專門用於向上一個活動傳遞資料,setResult有兩個參數,第一個是返回處理結果,RESULT_OK或者RESULT_CANCELED。第二個參數是把帶有資料的intent傳遞迴去。
7.活動的生命週期:(一定弄明白,記在心裡!)
onCreate
onStart
onResume
onPause
onStop
onDestroy
onRestart
8.進度條
final ProgressDialog pd = ProgressDialog.show(AtyMessage.this,getResources().getString(R.string.connecting),getResources().getString(R.string.connecting_to_server));
pd.dismiss();
Android第二天