一区二区日本_久久久久久久国产精品_无码国模国产在线观看_久久99深爱久久99精品_亚洲一区二区三区四区五区午夜_日本在线观看一区二区

Android顯示Intent示例含代碼

Android顯示Intent示例

Android顯示intent 指定要從活動調用的組件。愛掏網 - it200.com換句話說,我們可以通過顯示intent在Android中調用另一個活動。愛掏網 - it200.com

我們還可以使用顯示intent將信息從一個活動傳遞到另一個活動。愛掏網 - it200.com

在這里,我們將看到一個示例,調用一個活動從另一個活動,并且反過來也是如此。愛掏網 - it200.com

Android從一個活動調用另一個活動的示例

讓我們來看一個簡單的示例,Android顯示用例從另一個活動調用一個活動,反之亦然。愛掏網 - it200.com

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>  
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:app="http://schemas.android.com/apk/res-auto"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context="example.javatpoint.com.explicitintent.FirstActivity">  

    <TextView  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_marginEnd="8dp"  
        android:layout_marginStart="8dp"  
        android:layout_marginTop="8dp"  
        android:text="First Activity"  
        app:layout_constraintBottom_toBottomOf="parent"  
        app:layout_constraintEnd_toEndOf="parent"  
        app:layout_constraintHorizontal_bias="0.454"  
        app:layout_constraintLeft_toLeftOf="parent"  
        app:layout_constraintRight_toRightOf="parent"  
        app:layout_constraintStart_toStartOf="parent"  
        app:layout_constraintTop_toTopOf="parent"  
        app:layout_constraintVertical_bias="0.06" />  

    <Button  
        android:id="@+id/button"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_marginEnd="8dp"  
        android:layout_marginStart="8dp"  
        android:layout_marginTop="392dp"  
        android:onClick="callSecondActivity"  
        android:text="Call second activity"  
        app:layout_constraintEnd_toEndOf="parent"  
        app:layout_constraintStart_toStartOf="parent"  
        app:layout_constraintTop_toTopOf="parent" />  

</android.support.constraint.ConstraintLayout>  

ActivityOne 類

package example.javatpoint.com.explicitintent;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class FirstActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first);
    }
    public void callSecondActivity(View view){
        Intent i = new Intent(getApplicationContext(), SecondActivity.class);
        i.putExtra("Value1", "Android By Javatpoint");
        i.putExtra("Value2", "Simple Tutorial");
        // Set the request code to any code you like, you can identify the
        // callback via this code
        startActivity(i);
    }

}

activitytwo_main.xml

<?xml version="1.0" encoding="utf-8"?>  
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:app="http://schemas.android.com/apk/res-auto"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context="example.javatpoint.com.explicitintent.SecondActivity">  

    <TextView  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_marginEnd="8dp"  
        android:layout_marginStart="8dp"  
        android:layout_marginTop="8dp"  
        android:text="Second Activity"  
        app:layout_constraintBottom_toBottomOf="parent"  
        app:layout_constraintEnd_toEndOf="parent"  
        app:layout_constraintHorizontal_bias="0.454"  
        app:layout_constraintLeft_toLeftOf="parent"  
        app:layout_constraintRight_toRightOf="parent"  
        app:layout_constraintStart_toStartOf="parent"  
        app:layout_constraintTop_toTopOf="parent"  
        app:layout_constraintVertical_bias="0.06" />  

    <Button  
        android:id="@+id/button"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_marginEnd="8dp"  
        android:layout_marginStart="8dp"  
        android:layout_marginTop="392dp"  
        android:onClick="callFirstActivity"  
        android:text="Call first activity"  
        app:layout_constraintEnd_toEndOf="parent"  
        app:layout_constraintStart_toStartOf="parent"  
        app:layout_constraintTop_toTopOf="parent" />  
</android.support.constraint.ConstraintLayout>  

ActivityTwo類

package example.javatpoint.com.explicitintent;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class SecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        Bundle extras = getIntent().getExtras();
        String value1 = extras.getString("Value1");
        String value2 = extras.getString("Value2");
        Toast.makeText(getApplicationContext(),"Values are:\n First value: "+value1+
                "\n Second Value: "+value2, Toast.LENGTH_LONG).show();
    }
    public void callFirstActivity(View view){
        Intent i = new Intent(getApplicationContext(), FirstActivity.class);
        startActivity(i);
    }

}

輸出:

聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。
發表評論
更多 網友評論0 條評論)
暫無評論

返回頂部

主站蜘蛛池模板: 热re99久久精品国99热观看 | 日本污视频| 国产精品久久久久久久久久了 | 欧美精品乱码久久久久久按摩 | 五月天婷婷激情 | 国产精品乱码一二三区的特点 | 国产成人精品a视频一区www | 欧美精品一区三区 | 亚洲逼院 | 国产精品www | 依人成人| 99久9| 日本免费小视频 | 亚洲欧美在线观看 | 亚洲精品久久久久久一区二区 | 日韩中文字幕一区二区 | 精品日本中文字幕 | 最新中文字幕一区 | 欧美三级视频在线观看 | 欧美一级毛片久久99精品蜜桃 | 91综合网| 2018天天干天天操 | 香蕉二区| 日韩在线不卡 | 天天视频成人 | 狠狠操在线 | 亚洲一区视频在线播放 | 热久色 | 亚洲国产精品一区在线观看 | 91小视频在线 | 操网站| 在线一区二区三区 | 日韩在线大片 | 成人在线视频观看 | 99tv| 国产中的精品av涩差av | 日韩午夜精品 | 日韩欧美国产一区二区三区 | 日韩中文字幕2019 | av在线天堂网 | 亚洲国产精品久久久久秋霞不卡 |