363
No
class MainActivity
package com.example.choi.mystudy16;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View v){
Intent intent=null;
switch (v.getId()){
case R.id.button1:
intent=new Intent(this, ImplicitActivity.class);
break;
case R.id.button2:
intent=new Intent(this, CommunicationActivity.class);
break;
}
startActivity(intent);
}
}
R.layout.activity_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.choi.mystudy16.MainActivity">
<Button
android:text="명시적 - 암시적 인텐트"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@android:color/holo_blue_light"
android:textColor="@android:color/background_light"
android:onClick="onClick"
/>
<Button
android:text="액티비티 통신"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="31dp"
android:id="@+id/button2"
android:background="@android:color/holo_orange_dark"
android:layout_below="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="@android:color/background_light"
android:onClick="onClick"
/>
</RelativeLayout>
class ImplicitActivity
package com.example.choi.mystudy16;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class ImplicitActivity extends AppCompatActivity {
Toast toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.implicit);
Button bt_dial=(Button)findViewById(R.id.bt_dial);
Button bt_call=(Button)findViewById(R.id.bt_call);
Button bt_contact=(Button)findViewById(R.id.bt_contact);
Button bt_website=(Button)findViewById(R.id.bt_website);
Button bt_sms=(Button)findViewById(R.id.bt_sms);
bt_dial.setOnClickListener(listener);
bt_call.setOnClickListener(listener);
bt_contact.setOnClickListener(listener);
bt_website.setOnClickListener(listener);
bt_sms.setOnClickListener(listener);
}
View.OnClickListener listener=new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri=null;
Intent intent=null;
switch (v.getId()){
case R.id.bt_dial:
tostShow("Dial");
uri=Uri.parse("tel:01012345678");
intent=new Intent(Intent.ACTION_DIAL, uri);
break;
case R.id.bt_call:
tostShow("Call");
uri=Uri.parse("tel:01012345678");
intent=new Intent(Intent.ACTION_CALL, uri);
break;
case R.id.bt_contact:
tostShow("Contact");
uri=Uri.parse("content://contacts/people/");
intent=new Intent(Intent.ACTION_VIEW, uri);
break;
case R.id.bt_website:
tostShow("WebSite");
uri=Uri.parse("http://macaronics.ga");
intent=new Intent(Intent.ACTION_VIEW, uri);
break;
case R.id.bt_sms:
tostShow("SMS");
intent=new Intent(Intent.ACTION_VIEW);
intent.putExtra("sms_body", "문자 메시지 입니다.");
intent.setType("vnd.android-dir/mms-sms");
break;
}
if(intent!=null)startActivity(intent);
}
};
public void tostShow(String message){
if(toast==null){
toast=Toast.makeText(ImplicitActivity.this, message, Toast.LENGTH_SHORT);
}else{
toast.setText(message);
}
toast.show();
}
}
R.layout.implicit
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/implicit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.choi.mystudy16.ImplicitActivity">
<TextView
android:text="암시적 인텐트"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="normal|bold"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="@android:color/holo_red_dark" />
<Button
android:text="Contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:id="@+id/bt_contact"
android:background="@android:color/holo_orange_dark"
android:textColor="#ffffff"
/>
<Button
android:text="Web Site"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/bt_contact"
android:layout_centerHorizontal="true"
android:layout_marginTop="39dp"
android:id="@+id/bt_website"
android:textAllCaps="false"
android:background="@android:color/holo_purple"
android:textColor="#ffffff"
/>
<Button
android:text="SMS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/bt_website"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp"
android:id="@+id/bt_sms"
android:textAllCaps="false"
android:background="@android:color/holo_red_light"
android:textColor="#ffffff"
/>
<Button
android:text="Dial"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:id="@+id/bt_dial"
android:textAllCaps="false"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@android:color/holo_blue_dark"
android:textColor="#ffffff"
/>
<Button
android:text="Call"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
android:id="@+id/bt_call"
android:textAllCaps="false"
android:layout_below="@+id/bt_dial"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@android:color/holo_green_dark"
android:textColor="#ffffff"
/>
</RelativeLayout>
class CommunicationActivity
package com.example.choi.mystudy16;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class CommunicationActivity extends AppCompatActivity {
final static int USER_INFO = 0;
Button bt_go_second, bt_go_third;
EditText editText1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.communication);
bt_go_second=(Button)findViewById(R.id.bt_go_second);
bt_go_third=(Button)findViewById(R.id.bt_go_third);
editText1=(EditText)findViewById(R.id.editText1);
bt_go_second.setOnClickListener(listener);
bt_go_third.setOnClickListener(listener);
}
View.OnClickListener listener=new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=null;
switch (v.getId()){
case R.id.bt_go_second:
intent=new Intent(CommunicationActivity.this, SecondActivity.class);
intent.putExtra("u_id", "abc");
intent.putExtra("u_pw", 1234);
startActivity(intent);
break;
case R.id.bt_go_third:
intent=new Intent(CommunicationActivity.this, ThirdActivity.class);
intent.putExtra("u_id", "abc");
intent.putExtra("u_pw", 1234);
startActivityForResult(intent, CommunicationActivity.USER_INFO);
break;
}
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
switch (requestCode) {
case CommunicationActivity.USER_INFO:
if (resultCode == ThirdActivity.LOG_IN_OK) {
editText1.setText("LogIn Success!, " + intent.getStringExtra("user_info"));
} else if (resultCode == ThirdActivity.LOG_IN_NG){
editText1.setText("LogIn Fail!, " + intent.getStringExtra("user_info"));
}
break;
}
};
}
R.layout.communication
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/communication"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.choi.mystudy16.CommunicationActivity">
<TextView
android:text="액티비티 통신"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:textSize="24sp"
android:textAlignment="center"
android:textStyle="normal|bold"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:text="두번째 액티비티"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bt_go_second"
android:layout_below="@+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="21dp"
android:background="@android:color/holo_green_dark"
android:textStyle="normal|bold"
android:textColor="@android:color/background_light" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:layout_below="@+id/bt_go_third"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="71dp"
android:id="@+id/editText1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:hint="액티비티 통신 반환된 값 " />
<Button
android:text="세번째 액티비티"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="44dp"
android:id="@+id/bt_go_third"
android:background="@android:color/holo_orange_dark"
android:textColor="@android:color/background_light"
android:textStyle="normal|bold"
android:layout_below="@+id/bt_go_second"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
class SecondActivity
package com.example.choi.mystudy16;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class SecondActivity extends AppCompatActivity {
TextView tv=null;
Button btn=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
tv =(TextView)findViewById(R.id.tv_second);
btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(listener);
Intent intent=getIntent();
String u_id =intent.getStringExtra("u_id");
int u_pw =intent.getIntExtra("u_pw", 0);
tv.setText("아이디 : " + u_id + " , 비번 : " + u_pw);
}
View.OnClickListener listener=new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
finish();
break;
default:
break;
}
}
};
}
R.layout.second
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.choi.mystudy16.SecondActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv_second"
android:layout_alignParentTop="true"
android:textAlignment="center"
android:textStyle="normal|bold"
android:textSize="24sp" />
<Button
android:text="이전화면 가기"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_second"
android:layout_marginTop="78dp"
android:id="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
class ThirdActivity
package com.example.choi.mystudy16;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class ThirdActivity extends AppCompatActivity {
final static String TAG = "ThirdAcitivity";
final static int LOG_IN_OK = 0;
final static int LOG_IN_NG = 1;
TextView textView3;
Button btn = null;
boolean loginFlag = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.third);
textView3 = (TextView) findViewById(R.id.textView3);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(listener);
Intent intent = getIntent();
String u_id = intent.getStringExtra("u_id");
int u_pw = intent.getIntExtra("u_pw", 0);
if (Constant.DEBUG_MODE) {
Log.i(TAG, "u_id :" + u_id);
Log.i(TAG, "u_pw : " + u_pw);
}
textView3.setText("아이디 : " + u_id + ", 비번 : " + u_pw);
if (u_id.equals("abc") && u_pw == 1234) {
loginFlag = true;
} else {
loginFlag = false;
}
if (Constant.DEBUG_MODE) {
Log.i(TAG, "loginFlag : " + loginFlag);
}
}
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn:
Intent intent = new Intent();
intent.putExtra("user_info", textView3.getText().toString());
Log.i(TAG, textView3.getText().toString());
if (loginFlag) {
setResult(ThirdActivity.LOG_IN_OK, intent);
} else {
setResult(ThirdActivity.LOG_IN_NG, intent);
}
finish();
break;
}
}
};
}
R.layout.third
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/third"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.choi.mystudy16.ThirdActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:textAlignment="center"
android:textSize="24sp"
android:textStyle="normal|bold" />
<Button
android:text="이전화면 가기"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="83dp"
android:id="@+id/btn"
android:background="@android:color/holo_orange_dark"
android:textStyle="normal|bold"
android:textColor="@android:color/background_light"
android:layout_below="@+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
댓글 ( 4)
댓글 남기기