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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 推荐五款Android 应用的自动化测试
- 下一篇: android listview 数据同