继续学习Android,跟随第一行代码

来源:互联网 发布:看动漫学日语软件 编辑:程序博客网 时间:2024/04/28 01:33

学习Android四大组件之首——Activity。

创建项目,创建活动类extends Activity。重写onCreate(Bundle savedInstanceState)方法。参数 Bundle类是保存数据,类似Map,以键值对形式保存数据,让活动在创建是可以读取里面的数据以进行初始化。方法为putxxx()/getxxx();如putString(),getString()等。

<span style="font-size:24px;">public FirstActivity extends Activity{</span>
<span style="font-size:24px;"><span style="white-space:pre"></span>protected onCreate(Bundle savedInstanceState){</span>

<span style="font-size:24px;"><span style="white-space:pre"></span>super.onCreate(savedInstanceState);</span>
<span style="font-size:24px;"><span style="white-space:pre"></span>setContentView(R.layout.main);</span>
<span style="font-size:24px;"><span style="white-space:pre"></span>Toast.makeText(FirstActivity.this,"弹出短时提醒",Toast.LENGTH_SHORT).show();</span>
<span style="white-space:pre"></span>     <span style="font-size:24px;">Intent intent=new (FirstActivity.this,SecendActivity.class);//显示启动第二个活动</span>
<span style="font-size:24px;"><span style="white-space:pre"></span>intent.putExtra("key",value);</span>
</pre><p><pre name="code" class="java"><span style="font-size:24px;">}</span>
<span style="font-size:24px;"><span style="white-space:pre"></span></span>
<span style="font-size:24px;">}</span>


0 0
原创粉丝点击