#MainActivity.java
package com.example.s10;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
EditText edt_name, edt_age;
Button btn_send, btn_exit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt_name = (EditText)findViewById(R.id.edt_name);
edt_age = (EditText)findViewById(R.id.edt_age);
btn_send = (Button)findViewById(R.id.btn_send);
btn_exit = (Button)findViewById(R.id.btn_exit);
btn_send.setOnClickListener(this);
btn_exit.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(arg0.getId() == R.id.btn_exit){
finish();
}else {
Intent i = new Intent(this, bactivity.class);
i.putExtra("NAME", edt_name.getText().toString());
i.putExtra("AGE", edt_age.getText().toString());
startActivityForResult(i,2);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 2){
if(resultCode == RESULT_OK){
Toast.makeText(this, "받은값" + data.getExtras().getString("HOME"), Toast.LENGTH_LONG).show();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
#bactivity.java
package com.example.s10;
import android.app.Activity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class bactivity extends Activity {
TextView tv_result;
Button btn_close;
String name, age;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.bactivity);
Intent ri = getIntent();
name = ri.getExtras().getString("NAME");
age = ri.getExtras().getString("AGE");
tv_result = (TextView)findViewById(R.id.tv_result);
btn_close = (Button)findViewById(R.id.btn_close);
tv_result.setText("이름:"+name+" 나이:"+ age);
btn_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent si = new Intent(bactivity.this, MainActivity.class);
si.putExtra("HOME", "대구 수성구");
setResult(Activity.RESULT_OK,si);
finish();
}
});
}//onCreate
}
Manifest.java
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.s10"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.s10.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>
<activity android:name="bactivity"></activity>
</application>
</manifest>
'이전것 > 개발' 카테고리의 다른 글
CR -> CO -> CA (0) | 2016.07.20 |
---|---|
PLM -> 3d Experience Platform Install (0) | 2016.07.11 |
android -> Server -> xml (0) | 2016.07.08 |
android -> Server -> android (0) | 2016.07.08 |
android -> webServer (0) | 2016.07.08 |