日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

intent android 匿名,Android 匿名启动activity 启动系统activity

發布時間:2023/12/13 Android 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 intent android 匿名,Android 匿名启动activity 启动系统activity 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一般我們使用Intent 進行activity跳轉時我們都知道需要跳轉的activity的名字,例如:

Intent intent=new Intent(FirstActivity.this,SecondActitivy.class);

startActivity(intent);

當SecondActitivy.class和FirstActivity不再同一個App的時候,我們就需要用到匿名啟動,

匿名啟動:

首先需要設置被啟動的SecondActivity 的xml配置文件:

FirstActivity 可以利用

來找到 SecondActivity

FirstActivity代碼如下:

Intent intent=new Intent();

intent.setAction("toSecondPage");

startActivity(intent);

這樣就可以利用ActionName調到非本App的Activity

啟動系統activity也是這樣實現:

通過一個系統提供的ActionName來跳轉到系統的Activity,同時可以附加一些消息;(xml 就是4個簡單的按鈕)

package testIntent;

import java.net.URL;

import android.app.Activity;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import com.example.androidtest.R;

public class FirstActivity extends Activity implements OnClickListener{

private Button toWeBButton;

private Button toPicButton;

private Button toMesButton;

private Button toPhoneButton;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.first_activity_main);

toWeBButton=(Button) findViewById(R.id.toWeb);

toPicButton=(Button) findViewById(R.id.toPic);

toMesButton=(Button) findViewById(R.id.toMes);

toPhoneButton=(Button) findViewById(R.id.toPhone);

toWeBButton.setOnClickListener(this);

toPicButton.setOnClickListener(this);

toMesButton.setOnClickListener(this);

toPhoneButton.setOnClickListener(this);

}

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

Intent intent=new Intent();

if(v.equals(toWeBButton)){//跳轉到 網頁 百度首頁

intent.setAction(Intent.ACTION_VIEW);

Uri uri=Uri.parse("https://www.baidu.com");

intent.setData(uri);

}else if(v.equals(toPicButton)){//打開系統圖片

intent.setAction(Intent.ACTION_GET_CONTENT);

intent.setType("image/*");//打開所有的圖片, 如果需要獲取圖片就需要寫回調函數

}else if(v.equals(toMesButton)){//發送消息

intent.setAction(Intent.ACTION_SEND);

intent.setType("text/plain");

intent.putExtra(Intent.EXTRA_TEXT, "這是我第一次這樣發信息");

}else if(v.equals(toPhoneButton)){//撥打電話

intent.setAction(Intent.ACTION_VIEW);

Uri uri=Uri.parse("tel:1839860592");

intent.setData(uri);

}

startActivity(intent);

}

}

總結

以上是生活随笔為你收集整理的intent android 匿名,Android 匿名启动activity 启动系统activity的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。