Mm

1. ac01 mmsmaA:

Intent in = new Intent(ac01.this, pickup.class); startActivity(in);

MfsA^K Activity : pickup °

2. pickup mmsmaA:

Editor passwdfile = getSharedPreferences("ITEM", 0).edit(); passwdfile.putString("ITEM",item.getTitle().toString());

passwdfile.commit();

MAfU finish()MAISAft<ffiAM ' item lAitAA SharedPreferences

SharedPreferences passwdfile = getSharedPreferences(MITEMM, 0); String im = passwdfile.getString("ITEM", null); TextView tv = (TextView)findViewById(R.id.?v); tv.setText("choice: " + im);

SharedPreferences fMWXX item mil ' TextView ± °

6.2 #14: EM startActivityForResult()

startActivity()

±—MMffi ' ac01 ^EM starActivityOS^TO pickup = S^Mffl ActivityM^#^gBm^g(Process)ffi^^ ' Xt^««^-^®»-^ ' E mmmmn ° MMMft SharedPreferences °

^S^ffl^tt^AmXS ' mm^M startActivityForResult()®»^TOS-ffi Activity - MM® ' ' ESSitM °

MUH^H (Sequence Diagram)ffi±-ffiMmJIH^HmT-fir ' S^ft^

Sequence Diagram From Bowling Game App

H 6-3 iM startActivityForResultO^ftlffH

---- 2 : pressPickup()^iM^TM±ft Menu ^IM<Pick Up An

Item> I M ° faM ' ac01 i fr i ffl A ^ f ^ Android g ^ ffi ft startActivityForResultO®^A^A(W^^)pickup Activity ftA^^)

---- 3 : pickUpAnItem()^^iM#Tpu_layoutM±ft Menu IMIM^ ffllP! ° faM ' pickup ifrifflffiWAIMfti«»^®«^ ac01 ifr » ac01 °

' (MA^AM 5 ' 7AAM^<Show Result> MM ' SfmilAAiMMft TextView 7 °

package com.misoo.ex01_02; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView;

public class ac01 extends Activity {

public static final int PICKUPID = Menu.FIRST; public static final int EXITID = Menu.FIRST + 1; static final int PICKUPREQUEST = 0;

@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout./wa/'w); }

@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(0, PICKUP ID, 0, "Pick Up An Item"); menu.add(1, EXITID, 1, "Exit"); return true; }

@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case PICKUPID:

Intent in = new Intent(ac01.this, pickup.class); startActivityForResult(in, PICKUPREQUEST); return true; case EXITID: finish(); return true;

return super.onOptionsItemSelected(item);

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PICKUPREQUEST) { if (resultCode == RESULTCANCELED)

setTitle("Canceled..."); else if(resultCode == RESULTOK) {

TextView tv = (TextView)findViewById(R.id.iv);

String data_str = (String)data.getCharSequenceExtra("DataKey");

// — pickup.java fMA® — package com.misoo.ex01_02; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem;

public class pickup extends Activity {

public static final int ITEM1ID = Menu.FIRST; public static final int ITEM_2_ID = Menu.FIRST + 1; public static final int ITEM3ID = Menu.FIRST + 2;

@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout./wain); } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu);

menu.add(0, ITEM1ID, 0, "item-1"); menu.add(0, ITEM2ID, 1, "item-2"); menu.add(0, ITEM 3 ID, 2, "item-3"); return true; }

@Override public boolean onOptionsItemSelected(MenuItem item) { Bundle bundle = new Bundle(); bundle .putString("DataKey", item. getTitle().toString()); Intent mIntent = new Intent();

mIntent.putExtras(bundle); setResult(RESULT_OK, mIntent); finish();

return super.onOptionsItemSelected(item);

0 0

Post a comment