민서네집

[android] intent를 설정하는 여러가지 방법 본문

andorid

[android] intent를 설정하는 여러가지 방법

브라이언7 2010. 9. 14. 17:10


package my.andr.screen;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class FirstActivity extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  Button b = (Button) findViewById(R.id.next);
  b.setOnClickListener(new OnClickListener() {

   public void onClick(View v) {
    Intent i = new Intent();
    //i.setClass(FirstActivity.this, NextActivity.class);
    
//    ComponentName cn = new ComponentName("my.andr.screen", "my.andr.screen.NextActivity");
//    i.setComponent(cn);
//    startActivity(i);
    
    //i.setAction("android.intent.action.MAIN");
    //i.setAction(Intent.ACTION_MAIN); // 위의 코드 대신 사용 가능
    //i.addCategory("android.intent.category.DEFAULT"); //생략 가능
    
    //i.setAction("my.andr.main");
    
//    i.setAction(Intent.ACTION_DIAL);
//    i.setData(Uri.parse("tel:119"));
    
    i.setAction(Intent.ACTION_VIEW);
    i.setData(Uri.parse("http://www.naver.com/"));
    startActivity(i);
   }
  });
  System.out.println("onCreate()");
  Toast.makeText(this, "onCreate()", 100).show();
  Log.i("life", "onCreate()");
 }

 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  System.out.println("onPause()");
  Toast.makeText(this, "onPause()", 100).show();
  Log.i("life", "onPause()");
 }

 @Override
 protected void onRestart() {
  // TODO Auto-generated method stub
  super.onRestart();
  System.out.println("onRestart()");
  Toast.makeText(this, "onRestart()", 100).show();
  Log.i("life", "onRestart()");
 }

 @Override
 protected void onDestroy() {
  // TODO Auto-generated method stub
  super.onDestroy();
  System.out.println("onDestroy()");
  Toast.makeText(this, "onDestroy()", 100).show();
  Log.i("life", "onDestroy()");  
 }

 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
  System.out.println("onResume()");
  Toast.makeText(this, "onResume()", 100).show();
  Log.i("life", "onResume()");
 }

 @Override
 protected void onStart() {
  // TODO Auto-generated method stub
  super.onStart();
  System.out.println("onStart()");
  Toast.makeText(this, "onStart()", 100).show();
  Log.i("life", "onStart()");
 }

 @Override
 protected void onStop() {
  // TODO Auto-generated method stub
  super.onStop();
  System.out.println("onStop()");
  Toast.makeText(this, "onStop()", 100).show();
  Log.i("life", "onStop()");
 }
}

'andorid ' 카테고리의 다른 글

[android] 이벤트 핸들링 방법  (0) 2010.09.14
Comments