自学Android之Activity:(四)使用Intent在Activity中跳转和传值(下)

转载请注明出处:http://blog.youkuaiyun.com/cc_xz/article/details/61205788
前言:

上一篇学习了使用Intent在Activity间进行跳转,以及在跳转的时候进行传值,这些只使用了很少一部分的Intent功能,而本篇我们将继续深入学习Intent的一些其他功能。

在本篇中,你将了解到:
1.隐式跳转Intent。
2.通过Intent打开其他APP。
3.通过Intent跳转至其他Activity后,关闭该Activity时返回数据。
4.通过Intent发送Bundle类型的数据。

准备工作:

首先我们要创建两个Activity,以及他们的Layout,再到Layout中添加需要使用到的组件,代码如下:
MainActivity的Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/TextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:text="这是主活动" />

    <Button
        android:id="@+id/ButtonIntentHide"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="隐式跳转" />

    <Button
        android:id="@+id/ButtonIntentHttp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="打开浏览器" />

    <Button
        android:id="@+id/ButtonIntentReturnData"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="返回数据" />
</LinearLayout>

MainActivity:

public class MainActivity extends AppCompatActivity {
   
   
    private String TAG = "来自于MainActivity";
    private Button mButtonIntentHide, mButtonIntentHttp, mButtonIntentReturnData;
    private TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mButtonIntentHide = (Button) findViewById(R.id.ButtonIntentHide);
        mButtonIntentHttp = (Button) findViewById(R.id.ButtonIntentHttp);
        mButtonIntentReturnData = (Button) findViewById(R.id.ButtonIntentReturnData);
        mTextView = (TextView) findViewById(R.id.TextView);

        mButtonIntentHide.setOnClickListener(new View.OnClickListener() 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值