一区二区日本_久久久久久久国产精品_无码国模国产在线观看_久久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 條評論)
暫無評論

返回頂部

主站蜘蛛池模板: 国产精品一区一区三区 | 九九视频在线观看视频6 | 国产麻豆乱码精品一区二区三区 | 在线观看免费福利 | 精品一区二区三区不卡 | 中文字幕免费中文 | 免费国产网站 | 丁香婷婷久久久综合精品国产 | 一区二区三区高清 | 日本成人二区 | 日韩在线一区二区三区 | 色综合一区二区 | 日韩视频观看 | 天天操伊人 | a级黄色毛片免费播放视频 国产精品视频在线观看 | 日韩精品福利 | 午夜手机在线视频 | 日韩一二三区视频 | 七七婷婷婷婷精品国产 | 亚洲欧美在线一区 | 国产激情亚洲 | 91视频网址 | 国产亚洲欧美在线 | 日韩精品亚洲专区在线观看 | 成人国产免费视频 | 欧美中文字幕在线观看 | 亚洲精品乱码久久久久久黑人 | 日韩三极 | 99精品视频一区二区三区 | 欧美日韩中文在线 | 中文字幕亚洲视频 | 欧美三级在线 | 久久精品小视频 | 亚洲精品成人av | 亚洲v日韩v综合v精品v | 亚洲高清在线 | 成人乱人乱一区二区三区软件 | 欧美理伦片在线播放 | av天天操 | 国精日本亚洲欧州国产中文久久 | 久久久久久久久久久成人 |