インテントとは画面を複数連携させる仕組みのことを言います。
例えば、ボタンを押すと、別の画面に遷移するにはインテントを使用します。android.content.Intentを使用します。
以下、ボタンクリック時の実装例です。
public void onClick(View view){
Intent it = new Intent();
it.setAction(Intent.ACTION_VIEW);
it.setData(Uri.parse("tel:00000000"));
startActivity(it); // クリック時にこのアクティビティを起動
}
以下、電話アプリを起動するソースと実行例です。
package jp.co.confrage;
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 android.widget.LinearLayout;
public class Android003Activity extends Activity {
/** Called when the activity is first created. */
Button bt1 = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
setContentView(ll);
bt1 = new Button(this);
bt1.setText("Push Push!");
ll.addView(bt1);
bt1.setOnClickListener(new dialogClickListener());
}
class dialogClickListener implements OnClickListener{
public void onClick(View view){
Intent it = new Intent();
it.setAction(Intent.ACTION_VIEW);
it.setData(Uri.parse("tel:00000000"));
startActivity(it);
}
}
}
画面が起動したらボタンを押します。すると以下のように他画面が表示されます。