Created
March 22, 2016 04:45
-
-
Save bg1bgst333/bf6aff600b6801309f1e to your computer and use it in GitHub Desktop.
Intent#Intent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" > | |
<Button | |
android:id="@+id/button1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/button1_text" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.bgstation0.android.sample.intent_" | |
android:versionCode="1" | |
android:versionName="1.0" > | |
<uses-sdk | |
android:minSdkVersion="15" | |
android:targetSdkVersion="15" /> | |
<application | |
android:allowBackup="true" | |
android:icon="@drawable/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme" > | |
<activity | |
android:name=".MainActivity" | |
android:label="@string/app_name" > | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bgstation0.android.sample.intent_; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.Button; | |
public class MainActivity extends Activity implements OnClickListener{ // View.OnClickListenerを実装. | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// button1を取得し, OnClickListenerとして自身をセット. | |
Button button1 = (Button)findViewById(R.id.button1); // findViewByIdでR.id.button1を取得. | |
button1.setOnClickListener(this); // button1.setOnClickListenerでthis(自身)をセット. | |
} | |
// View.OnClickListenerインタフェースのオーバーライドメソッドを実装. | |
public void onClick(View v){ // onClickをオーバーライド. | |
// ボタンが押されたらインテントで"http://bg1hatenablog.com"を開くことができるアプリに渡して表示してもらう. | |
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://bg1.hatenablog.com")); // Intent.ACTION_VIEW(画面表示アクション)で"http://bg1.hatenablog.com"を表示するIntentオブジェクトintentを生成. | |
startActivity(intent); // startActivityでintentを指定して表示してくれるアプリを起動. | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<string name="app_name">Intent_</string> | |
<string name="hello_world">Hello world!</string> | |
<string name="button1_text">button1</string> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment