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

Android Intent教程含代碼

Android Intent教程

Android Intent 是在組件之間傳遞的消息,例如活動、內容提供者、廣播接收器、服務等。愛掏網 - it200.com

通常與startActivity()方法一起使用,用于調用活動、廣播接收器等。愛掏網 - it200.com

intent的字典意義 是意圖或目的。愛掏網 - it200.com因此,可以將其描述為執行操作的意圖。愛掏網 - it200.com

LabeledIntent是android.content.Intent類的子類。愛掏網 - it200.com

Android意圖主要用于:

  • 啟動服務
  • 啟動活動
  • 顯示網頁
  • 顯示聯系人列表
  • 廣播消息
  • 撥打電話等

Android有兩種類型的意圖:隱式意圖和顯示意圖。愛掏網 - it200.com

1) 隱式意圖

隱式意圖 不指定組件。愛掏網 - it200.com在這種情況下,意圖提供了系統提供的可調用組件的信息。愛掏網 - it200.com

例如,您可以編寫以下代碼來查看網頁。愛掏網 - it200.com

Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.javatpoint.com"));
startActivity(intent);

2) 明確意圖

明確意圖 指定了要調用的組件。愛掏網 - it200.com在這種情況下,意圖提供了要調用的外部類。愛掏網 - it200.com

Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
startActivity(i);

要獲取顯示顯式意圖的完整代碼,請訪問下一頁。愛掏網 - it200.com

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.implicitintent.MainActivity">  

    <EditText  
        android:id="@+id/editText"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_marginEnd="8dp"  
        android:layout_marginStart="8dp"  
        android:layout_marginTop="60dp"  
        android:ems="10"  
        app:layout_constraintEnd_toEndOf="parent"  
        app:layout_constraintHorizontal_bias="0.575"  
        app:layout_constraintStart_toStartOf="parent"  
        app:layout_constraintTop_toTopOf="parent" />  

    <Button  
        android:id="@+id/button"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_marginRight="8dp"  
        android:layout_marginLeft="156dp"  
        android:layout_marginTop="172dp"  
        android:text="Visit"  
        app:layout_constraintEnd_toEndOf="parent"  
        app:layout_constraintHorizontal_bias="0.0"  
        app:layout_constraintStart_toStartOf="parent"  
        app:layout_constraintTop_toBottomOf="@+id/editText" />  
</android.support.constraint.ConstraintLayout>

Activity類

package example.javatpoint.com.implicitintent;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    Button button;
    EditText editText;

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

        button = findViewById(R.id.button);
        editText =  findViewById(R.id.editText);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String url=editText.getText().toString();
                Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
            }
        });
    }
}

輸出:

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

返回頂部

主站蜘蛛池模板: 在线免费观看一区二区 | 国内在线视频 | 欧美日韩精品一区二区三区四区 | 国产精品视频一二三 | 国产在线精品一区二区三区 | 久久久蜜桃 | 欧美国产日韩在线观看 | 成人亚洲精品久久久久软件 | 99国产精品视频免费观看一公开 | 色资源在线观看 | 欧美日韩高清在线观看 | 日韩成人在线观看 | 精品视频一区二区 | 亚洲国产欧美日韩 | 午夜视频免费在线 | 久久69精品久久久久久久电影好 | 欧美性猛交一区二区三区精品 | 天天天天操 | 超碰超碰 | 狠狠操狠狠干 | 国产精品久久国产精品 | 国产日韩欧美精品一区二区三区 | 日本高清中文字幕 | 欧美性jizz18性欧美 | 91精品国产欧美一区二区 | 99精品一区二区三区 | 日韩国产精品一区二区三区 | 免费av直接看| 日韩一级欧美一级 | 久久国产精品免费一区二区三区 | 国产精品免费一区二区三区四区 | 国产在线精品一区二区 | 亚洲国产成人精品女人 | 91亚洲国产亚洲国产 | 在线a视频网站 | 亚洲精品456| 国产在线精品区 | 亚洲www.| 国产精品一级 | 国产精品久久久久一区二区三区 | 久久精品91久久久久久再现 |