FirstScreen.java
package org.kandroid.sample;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class FirstScreen extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.main);
        Button launchActivity = (Button) findViewById(R.id.my_button);
        
        launchActivity.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        Intent i = new Intent();
        
        
        ComponentName comp =
        new ComponentName("org.kandroid.sample",
        "org.kandroid.sample.SecondScreen");
        i.setComponent(comp);
        
        
        Log.i("FirstScreen","Button Clicked");
        
        startActivity(i);
        }
        });
    }
 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  
  Toast toast = Toast.makeText(FirstScreen.this, "1: onPause", Toast.LENGTH_LONG);
  toast.show();
 }
 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
  Toast toast = Toast.makeText(FirstScreen.this, "onResume", Toast.LENGTH_LONG);
  toast.show();
 }
    
}
SecondScreen.java
package org.kandroid.sample;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class SecondScreen extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second2);
    }
    
 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  
  Toast toast = Toast.makeText(SecondScreen.this, "2: onPause", Toast.LENGTH_LONG);
  toast.show();
 }
 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
  Toast toast = Toast.makeText(SecondScreen.this, "2: onResume", Toast.LENGTH_LONG);
  toast.show();
 }
    
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="첫번째 화면" 
    
    />
    
    <Button 
    android:id="@+id/my_button"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="이것은 버튼" 
    
    />
    
    
</LinearLayout>
second2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="두번째 화면" 
    
    />
</LinearLayout>
'Not Using > mobile contents' 카테고리의 다른 글
| 강의목록 (0) | 2009.11.16 | 
|---|---|
| 11.16 (0) | 2009.11.16 | 
| 모바일컨텐츠 - 이클립스연결 (0) | 2009.11.16 |