Skip to content

Instantly share code, notes, and snippets.

@yahyaahrika
Forked from bg1bgst333/AndroidManifest.xml
Created August 13, 2016 15:09
Show Gist options
  • Save yahyaahrika/b1a2daa9ebc925b8e7600a7c72f29b8e to your computer and use it in GitHub Desktop.
Save yahyaahrika/b1a2daa9ebc925b8e7600a7c72f29b8e to your computer and use it in GitHub Desktop.
Intent#Intent
<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>
<?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>
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を指定して表示してくれるアプリを起動.
}
}
<?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