Android第二天

來源:互聯網
上載者:User

標籤: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第二天

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.