转载请注明出处: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()