Artificial Intelligence Programming Lab(AIPLab) 討論區

程式語言摘要 => Java => Android => 主題作者是: admin 於 六月 04, 2017, 11:39:17 am



主題: <<Intent>>
作者: admin六月 04, 2017, 11:39:17 am
Intent物件
(1) Intent 是可用來向另一個應用程式元件要求動作的傳訊物件。

明確意圖範例
程式碼: [Select]
Intent downloadIntent = new Intent(this, DownloadService.class);
downloadIntent.setData(Uri.parse(fileUrl));
startService(downloadIntent);

隱含意圖範例
程式碼: [Select]
// Create the text message with a string
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage);
sendIntent.setType("text/plain");

// Verify that the intent will resolve to an activity
if (sendIntent.resolveActivity(getPackageManager()) != null) {
    startActivity(sendIntent);
}