Äú¿ÉÒÔ¾èÖú£¬Ö§³ÖÎÒÃǵĹ«ÒæÊÂÒµ¡£

1Ôª 10Ôª 50Ôª





ÈÏÖ¤Â룺  ÑéÖ¤Âë,¿´²»Çå³þ?Çëµã»÷Ë¢ÐÂÑéÖ¤Âë ±ØÌî



  ÇóÖª ÎÄÕ ÎÄ¿â Lib ÊÓÆµ iPerson ¿Î³Ì ÈÏÖ¤ ×Éѯ ¹¤¾ß ½²×ù Modeler   Code  
»áÔ±   
 
   
 
 
     
   
 ¶©ÔÄ
  ¾èÖú
°²×¿µÚ¾ÅÌì±Ê¼Ç-Activity
 
×÷ÕߣºÉ­ÁÖÉ­ À´×ÔÓÚ£º²©¿ÍÔ° ·¢²¼ÓÚ 2016-3-24
  2093  次浏览      27
 

1.´´½¨Activity

Ò»¸ö½çÃæ¶ÔÓ¦Ò»¸öactivity

´´½¨Ò»¸öActivity

1.дһ¸öJAVAÀà,¼Ì³ÐActivity

publicclass CalcActivity extends Activity {

2.ΪÕâ¸öActivityдһ¸ö²¼¾ÖÎļþ

3.ÔÚActivityÖÐÖØÐ´OnCreate()·½·¨,²¢ÉèÖÃÏÔʾµÄÄÚÈÝsetContentView(R.layout.xxx)xxx±íʾ²¼¾ÖÎļþµÄÃû³Æ

4.ÔÚManifest.xmlÎļþÖÐΪActivity×¢²á

<activity android:name="com.itheima.rp.CalcActivity"></activity>

2.ÈËÆ·¼ÆËãÆ÷

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

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=".LogoActivity" >

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/logo"/>

</RelativeLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_horizontal"

android:orientation="vertical" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="10dp"

android:text="ÈËÆ·¼ÆËãÆ÷"

android:textColor="#66ff0000"

android:textSize="32sp" />

<EditText

android:id="@+id/et_name"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="ÇëÊäÈëÄúµÄÐÕÃû" />

<Button

android:onClick="calc"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="¼ÆËã"/>

<TextView

android:id="@+id/tv_result"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

</LinearLayout>

LogoActivity

/**

* Logo½çÃæ

public class LogoActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_logo);

//´ò¿ªºóÏÔʾµÄLOGO½çÃæ

new Thread(){

public void run() {

//ÏÔʾ5ÃëºóÁ¬½Óµ½Çл»µ½ÏÂÒ»¸öActivity

SystemClock.sleep(5000);

startActivity(new Intent(LogoActivity.this, CalcActivity.class));

//¹Ø±ÕµôÕâ¸öActivity²»È»ºóÍ˾ÍÓֻص½Logo½çÃæÁË

finish();

};

}.start();

}

}

CalcActivity

/**

* ´´½¨Ò»¸öActivity

* 1.дһ¸öJAVAÀà,¼Ì³ÐActivity

* 2.ΪÕâ¸öActivityдһ¸ö²¼¾ÖÎļþ

* 3.ÔÚActivityÖÐÖØÐ´OnCreate()·½·¨,²¢ÉèÖÃÏÔʾµÄÄÚÈÝsetContentView(R.layout.xxx)xxx±íʾ²¼¾ÖÎļþµÄÃû³Æ

public class CalcActivity extends Activity {

private EditText et_name;

private TextView tv_result;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//ÉèÖÃÒªÏÔʾµÄÄÚÈݲ¼¾ÖÎļþ

setContentView(R.layout.activity_calc);

et_name = (EditText) findViewById(R.id.et_name);

tv_result = (TextView) findViewById(R.id.tv_result);

}

* ¼ÆËãÈËÆ·

* @param v

public void calc(View v){

//»ñÈ¡Ãû³Æ

String name = et_name.getText().toString().trim();

if(TextUtils.isEmpty(name)){

Toast.makeText(this, "ÐÕÃû²»ÄÜΪ¿Õ", Toast.LENGTH_SHORT).show();

return;

}

//²»Îª¿Õ¾Í¿ªÊ¼¼ÆËã

byte[] bytes = name.getBytes();

//½á¹û

int sum=0;

for (byte b : bytes) {

int tmp=b&0xff;

sum+=tmp;

}

//¿ªÊ¼¼ÆËãÈËÆ·

int rp=sum/100;

if (rp>9) {

tv_result.setText("ÈËÃû:"+name+"--->ÈËÆ·:"+rp+"===ÈËÆ·Ë§µ½µôÔü,µ±ÊÀµÄ»îÆÐÈø");

}else if(rp>6){

tv_result.setText("ÈËÃû:"+name+"--->ÈËÆ·:"+rp+"===Ò»°ãÒ»°ãÊÀ½çµÚÈý,");

}else{

tv_result.setText("ÈËÃû:"+name+"--->ÈËÆ·:"+rp+"===Éϱ²×ÓûÓиɻµÊÂ,ºÃºÃ»î×Å");

}

}

}

¼ÆËãºÍ½á¹û¶¼ÔÚÒ»¸ö½çÃæÍê³ÉµÄ,

ÏÂÃæÔÙ¼ÓÒ»¸ö½çÃæÖ»ÓÃÓÚÏÔʾ½á¹û

²¢°ÑͼƬ´ø¹ýÈ¥

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_horizontal"

android:orientation="vertical" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="½á¹ûÏÔʾ"/>

<ImageView

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

<TextView

android:id="@+id/tv_result"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

</LinearLayout>

Activity

¸ü¸ÄCalcActivity

//¿ªÊ¼¼ÆËãÈËÆ·

String str;

int rp=sum/100;

if (rp>9) {

str="ÈËÃû:"+name+"--->ÈËÆ·:"+rp+"===ÈËÆ·Ë§µ½µôÔü,µ±ÊÀµÄ»îÆÐÈø";

}else if(rp>6){

str="ÈËÃû:"+name+"--->ÈËÆ·:"+rp+"===Ò»°ãÒ»°ãÊÀ½çµÚÈý,";

}else{

str="ÈËÃû:"+name+"--->ÈËÆ·:"+rp+"===Éϱ²×ÓûÓиɻµÊÂ,ºÃºÃ»î×Å";

}

// ·¢ËÍÊý¾Ýµ½ÁíÍâÒ»¸öActivity

Intent intent = new Intent();

intent.setClass(this, ResultActivity.class);

//Ìí¼ÓÊý¾Ý×Ö·û´®

intent.putExtra("data", str);

//°ÑͼƬµÄID·Åʱȥ

intent.putExtra("rp", R.drawable.logo);

startActivity(intent);

½á¹ûÒ³Ãæ²¼¾Ö

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_horizontal"

android:orientation="vertical" >

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="½á¹ûÏÔʾ"/>

<ImageView

android:id="@+id/iv_display"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

<TextView

android:id="@+id/tv_result"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="½á¹ûÏÔʾ"/>

</LinearLayout>


/**

* ´´½¨Ò»¸öActivity

* 1.дһ¸öJAVAÀà,¼Ì³ÐActivity

* 2.ΪÕâ¸öActivityдһ¸ö²¼¾ÖÎļþ

* 3.ÔÚActivityÖÐÖØÐ´OnCreate()·½·¨,²¢ÉèÖÃÏÔʾµÄÄÚÈÝsetContentView(R.layout.xxx)xxx±íʾ²¼¾ÖÎļþµÄÃû³Æ

public class ResultActivity extends Activity {

private TextView tv_result;

private ImageView iv_display ;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//ÉèÖÃÒªÏÔʾµÄÄÚÈݲ¼¾ÖÎļþ

setContentView(R.layout.activity_result);

tv_result = (TextView) findViewById(R.id.tv_result);

iv_display = (ImageView) findViewById(R.id.iv_display);

//»ñÈ¡Intent

Intent intent = getIntent();

//»ñÈ¡Êý¾Ý

String data = intent.getStringExtra("data");

//ÉèÖÃÖµ

tv_result.setText(data);

//»ñȡͼƬ

int rpMap = intent.getIntExtra("rp", 0);

//ÉèÖÃͼƬ

iv_display.setImageResource(rpMap);

}

}

3.ʹÓÃIntent´«µÝ¶àÖÖÊý¾Ý

3.1´«µÝ¼òµ¥Êý¾Ý

Intent intent = new Intent();

intent.setClass(this, SecondActivity.class);

//´«µÝÆÕͨÊý¾Ý

intent.putExtra("name", "ÕÅÈý");

intent.putExtra("age", 18);

intent.putExtra("flag", true);

startActivity(intent);

3.2´«µÝ¸´ÔÓÊý¾Ý

1.´«µÝÒ»¸ö¶ÔÏó,¶ÔÏóµÄÀàҪʵÏÖParcelable

Intent intent = new Intent();

intent.setClass(this, SecondActivity.class);

//´«Ò»¸ö¶ÔÏó

//ǰÌá ÊÇpersonʵÏÖÁËParcelable½Ó¿Ú

Person person = new Person("Áõéª", 30);

intent.putExtra("person", person);

startActivity(intent);

»ñÈ¡

Intent intent = getIntent();

//»ñÈ¡Êý¾Ýn

String name = intent.getStringExtra("name");

int age = intent.getIntExtra("age", 2);

boolean flag = intent.getBooleanExtra("flag", false);

Person p=intent.getParcelableExtra("person");

Toast.makeText(this,p.toString(), Toast.LENGTH_SHORT).show();

ʵ¼ÊÉÏÖ»ÒªÈÃjavaBeanʵÏÖSerializable ½Ó¿Ú¾Í¿ÉÒÔÁË£¬²»¹ÜÊÇ´«µÝµ¥¸ö¶ÔÏ󣬻òÕßÊÇ´«µÝÒ»¸ö¼¯ºÏ£¬¶¼Ã»ÎÊÌâ¡£

4. Æô¶¯½çÃæµÄÁ½ÖÖ·½Ê½

4.1ÏÔʾÒâͼ

Ö»ÒªÖ¸¶¨ÉÏÏÂÎÄ£¬ºÍ¾ßÌåµÄÀà¾Í¿ÉÒÔÌø×ª

Äܹ»Ö±½ÓÖªµÀÌø×ªµÄ½çÃæ

×¢²á£º

<activity android:name="com.itheima.start.Activity01"></activity>

Ìø×ª£º

Intent intent = new Intent(this , Activity01.class);

startActivity(intent);

×÷Ó㺠һ°ãÊÇÆô¶¯×Ô¼º³ÌÐòµÄ½çÃæ£¬ÆäËû³ÌÐòµÄ½çÃæÍ¨¹ýÕâÖÖ·½Ê½ÎÞ·¨Æô¶¯

Èç¹ûʹÓÃÁËÏÔʽÊÖ·¨×¢²á£¬»¹Ïë±»ÆäËûÓ¦ÓóÌÐò´ò¿ª£¬ ÄÇô¿ÉÒÔÔÚactivity±êÇ©ÀïÃæ£¬¼ÓÉÏ

android:exported="true"

4.2 ÒþÄäÒâͼ

²»ÖªµÀÒª´ò¿ªµÄ½çÃæÊÇʲôÑù×ÓµÄ,Ö»ÓÐÔËÐÐÁ˲ÅÖªµÀ

ÒªÖ¸¶¨ActionÓëdata²Å¿ÉÒÔ

/**

* ÏÔʾÒâͼ´ò¿ªActivity02

* @param v

public void click1(View v){

Intent intent = new Intent();

intent.setClass(this, SencondActivity.class);

startActivity(intent);

}

<activity android:name="com.itheima.intentstart.SencondActivity"></activity>

ÒþÄäÒâͼҪָ¶¨Action,

<!--ÒþÄäÒâͼ  -->

<activity android:name="com.itheima.intentstart.SencondActivity">

<intent-filter >

<!--Action -->

<action android:name="com.itheima.intentstart.Second"/>

<!--ÉèÖÃΪĬÈ쵀 -->

<category android:name="android.intent.category.DEFAULT"/>

</intent-filter>

</activity>


/**

* ÒþʽÒâͼ´ò¿ªActivity02

* @param v

public void click2(View v) {

Intent intent = new Intent();

intent.setAction("com.itheima.intentstart.Second");

intent.addCategory("android.intent.category.DEFAULT");

startActivity(intent);

}

4.3 ²ÎÊý

×÷Óãº Ìø×ªÆäËûµÄÓ¦ÓóÌÐò½çÃæ£¬»òÕßÊÇ×Ô¼ºµÄÓ¦ÓóÌÐò½çÃæÏë±»ÆäËûµÄ³ÌÐò´ò¿ª

Ïêϸ²ÎÊý£º

action: ¶¯×÷

category ·ÖÀà

data: Ö¸¶¨Êý¾Ý£¬ Ò»°ã¹Ø×¢Á½¸ö£ºscheme ºÍ mimetype

android:scheme="itheima" android:path="www.itheima" android:mimeType="text/plain"

4.4ÒþÄäÒâͼ´ò´òSMS

<Button

android:onClick="shareSms"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="´ò¿ªÊÖ»ú¶ÌÐÅ" />


/**

* ÒþÄäÒâͼ ´ò¿ªÊÖ»úSMS½çÃæ

* Ô´Âë

* <intent-filter>

<action android:name="android.intent.action.VIEW" />

<action android:name="android.intent.action.SENDTO" />

<category android:name="android.intent.category.DEFAULT" />

<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="sms" />

<data android:scheme="smsto" />

</intent-filter>

* @param v

public void shareSms(View v){

Intent intent = new Intent();

intent.setAction("android.intent.action.VIEW");

intent.addCategory("android.intent.category.BROWSABLE");

intent.setData(Uri.parse("sms:"));

//ÉèÖÃÊý¾Ý

intent.putExtra("sms_body", "ÕâÊÇÒª´«¹ýÈ¥µÄÄÚÈÝ");

startActivity(intent);

}

µã»÷°´¼ü,ÏÔʾ½çÃæ

4.5 ´ò¿ªä¯ÀÀÆ÷

/**´ò¿ªÏµÍ³µÄä¯ÀÀÆ÷

* <intent-filter>

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="http" />

<data android:scheme="https" />

<data android:scheme="about" />

<data android:scheme="javascript" />

</intent-filter>

* @param v

public void onOPenBrower(View v){

Intent intent = new Intent();

intent.setAction("android.intent.action.VIEW");

intent.addCategory("android.intent.category.BROWSABLE");

intent.setData(Uri.parse("http://www.baidu.com"));

startActivity(intent);

}

5.¶à¸öActivityÖ®¼ä»ñÈ¡Êý¾ÝÓë´«µÝ

´ò¿ªÏÂÒ»¸ö½çÃæ£¬È»ºó·µ»ØÊý¾Ý

³¡¾°

QQÁÄÌì¸øºÃÓÑ·¢ËÍͼƬ (ÅÄÕÕ·µ»Ø¡¢ Ïà²áѡȡ)

Ñ¡ÔñÁªÏµÈËÓë¶ÌÐÅÄ£°æ°ÑÑ¡Ôñµ½µÄÄÚÈÝÏÔʾÔÚÖ¸¶¨µÄλÖÃ

Ö÷½çÃæ²¼¾Ö

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_horizontal"

android:orientation="vertical" >

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center_horizontal"

android:text="¶ÌÐÅ·¢ËÍÖúÊÖ"

android:textSize="30sp" />

<RelativeLayout

android:layout_width="match_parent"

android:layout_height="wrap_content" >

<EditText

android:id="@+id/et_contact"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="20sp"

android:hint="ÇëÊäÈëÁªÏµÈË" />

<!-- Ñ¡ÔñÁªÏµÈË -->

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:onClick="selectContact"

android:text="+" />

</RelativeLayout>

<EditText

android:id="@+id/et_content"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="20sp"

android:hint="ÇëÊäÈë¶ÌÐÅÄÚÈÝ"

android:minLines="8" />

<Button

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:onClick="selectSms"

android:text="Ñ¡Ôñ¶ÌÐÅÄ£°æ" />

<Button

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:onClick="sendSms"

android:text="·¢ËÍ" />

</LinearLayout>

¶ÌÐÅÁбí

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_horizontal"

android:orientation="vertical" >

<!--¶ÌÐÅÁбí -->

<ListView

android:id="@+id/lv_sms"

android:layout_width="match_parent"

android:layout_height="match_parent" >

</ListView>

</LinearLayout>

ÁªÏµÈËÁбí

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center_horizontal"

android:orientation="vertical" >

<!--ÁªÏµÈËÁбí -->

<ListView

android:id="@+id/lv_contact"

android:layout_width="match_parent"

android:layout_height="match_parent" >

</ListView>

</LinearLayout>


Ö÷½çÃæ

* ͨ¹ýÑ¡ÔñÁªÏµÈË,ÓëÄ£°æ°ÑÑ¡Ôñµ½µÄÄÚÈÝÏÔʾÔÚÖ¸¶¨µÄλÖÃ

1.½¨Á¢²¼¾Ö.ÉèÖõã»÷ʼþ

2.Ìø×ªµ½Ñ¡ÔñÒ³Ãæ

3.ʹÓÃListViewչʾÊý¾Ý

* 4.ΪListViewÉèÖÃOnItemClickListener¼àÌýÆ÷Óëʼþ°ÑÑ¡Ôñµ½µÄÊý¾Ý·µ»Ø¸øÇëÇó Activity

* 5.¹Ø±ÕÑ¡ÔñµÄActivity½áÊøfinish() 6

public class MainActivity extends Activity {

* ÁªÏµÈË

private EditText et_contact;

* ÄÚÈÝ

private EditText et_content;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

et_contact = (EditText) findViewById(R.id.et_contact);

et_content = (EditText) findViewById(R.id.et_content);

}

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

//ÅжϷµ»ØµÄintentÊÇ·ñΪ¿Õ

if(data==null){

return ;

}

//¸úËùÇëÇóÂëÇø±ðÊÇʲô½á¹û

switch (requestCode) {

case 100:

//ÉèÖÃÁ¬ÁªÏµÈË

et_contact.setText(data.getStringExtra("contact"));

break;

case 200:

//ÉèÖÃÄÚÈÝ

et_content.setText(data.getStringExtra("content"));

break;

}

}

* Ñ¡ÔñÁªÏµÈË

* @param v

public void selectContact(View v) {

Intent intent = new Intent();

intent.setClass(this, ContactActivity.class);

* requestCode:ËæÒâд, Èç¹ûÒ»¸öÒ³ÃæÄÚÓжà¸öÇëÇó½á¹ûµÄ񻂿·Ö

startActivityForResult(intent, 100);

}

* Ñ¡ÔñSMSÄ£°æ

public void selectSms(View v) {

Intent intent = new Intent();

intent.setClass(this, SmsActivity.class);

* requestCode:ËæÒâд, Èç¹ûÒ»¸öÒ³ÃæÄÚÓжà¸öÇëÇó½á¹ûµÄ񻂿·Ö

startActivityForResult(intent, 200);

}

* ·¢ËÍSMS

public void sendSms(View v) {

String number = et_contact.getText().toString().trim();

String body = et_content.getText().toString().trim();

if(TextUtils.isEmpty(number) || TextUtils.isEmpty(body)){

Toast.makeText(this, "ÊÖ»úºÅ»òÕßÄÚÈݲ»ÄÜΪ¿Õ", Toast.LENGTH_SHORT).show();

return ;

}

* ·¢ËͶÌÐÅ

SmsManager manager = SmsManager.getDefault();

//²ð·Ö¶ÌÐÅ

ArrayList<String> divideMessage = manager.divideMessage(body);

for (String str : divideMessage) {

manager.sendTextMessage(number, null, str, null, null);

}

}

}

¶ÌÐÅÁбí

/**

* ¶ÌÐÅÄ£¿éÁбíÏÔʾ

public class SmsActivity extends Activity {

protected static final String TAG = "SmsActivity";

private ListView lv_sms;

private String [] objects={

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ1",

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ2",

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ3",

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ4",

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ5",

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ6",

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ7",

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ8",

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ9",

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ10",

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ11",

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ12",

"¶ÌÐÅÄ£¿éÁбíÏÔʾÄÚÈÝ45",

};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_sms_item);

lv_sms = (ListView) findViewById(R.id.lv_sms);

lv_sms = (ListView) findViewById(R.id.lv_sms);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, objects);

//ÅäÖüàÌýÆ÷

lv_sms.setAdapter(adapter);

//ÉèÖüàÌýʼþ

lv_sms.setOnItemClickListener(new OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> parent, View view,

int position, long id) {

Log.i(TAG, "position:"+position);

Log.i(TAG, "ÔªËØ:"+objects[position]);

//·µ»Ø·µ»ØresultCode ÏìÓ¦Âë

Intent intent = new Intent();

//±£´æ´«µÝµÄÊý¾Ý

intent.putExtra("content", objects[position]);

//µ÷Öýá¹û

setResult(200, intent);

//½áÊø

finish();

}

});

}

}

ÁªÏµÈËÁбí

/**

* ÁªÏµÈËÁбíÏÔʾ

public class ContactActivity extends Activity {

protected static final String TAG = "ContactActivity";

private ListView lv_contact;

private String [] objects ={

"5556",

"13800138000",

"13800138012",

"13800138023",

"13800138004",

"13800138025",

"13800138306",

"13800138007",

"13800138069",

};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_contact_item);

lv_contact = (ListView) findViewById(R.id.lv_contact);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, objects);

//ÅäÖüàÌýÆ÷

lv_contact.setAdapter(adapter);

//ÉèÖüàÌýʼþ

lv_contact.setOnItemClickListener(new OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> parent, View view,

int position, long id) {

Log.i(TAG, "position:"+position);

Log.i(TAG, "ÔªËØ:"+objects[position]);

//·µ»Ø·µ»ØresultCode ÏìÓ¦Âë

Intent intent = new Intent();

//±£´æ´«µÝµÄÊý¾Ý

intent.putExtra("contact", objects[position]);

//µ÷Öýá¹û

setResult(200, intent);

//½áÊø

finish();

}

});

}

}

Ìí¼ÓȨÏÞ

<uses-permission android:name="android.permission.SEND_SMS"/>

6.ÉúÃüÖÜÆÚ

###ActivityÉúÃüÖÜÆÚ

* ÉúÃüÖÜÆÚ

> Ò»Àà´Ó³öÉúµ½ÏûÍöµÄ¹ý³Ì£¨Ê±¼ä¶Î£©

* ÉúÃüÖÜÆÚ·½·¨

> ¶ÔÏó´Ó´´½¨µ½Ïú»Ù£¬Ëùµ÷Óõķ½·¨¡£

* ´´½¨ÓëÏú»Ù

> onCreate ºÍ onDestroy Êý¾ÝµÄ±£´æºÍ»ØÏÔ¹¤×÷

* ¿É¼ûÓë²»¿É¼û

> onStart ºÍ onStop ¿É¼ûµÄʱºò²¥·ÅÊÓÆµ£¬²»¿É¼ûµÄʱºòÔÝÍ£ÊÓÆµµÄ²¥·Å

* »ñÈ¡½¹µãºÍʧȥ½¹µã

> onResume ºÍ onPause

###ÉúÃüÖÜÆÚ×ܽá

* entire lifetime

> ÍêÕûÉúÃüÖÜÆÚ onCreate-- onStart-- onResume -- onPause -- onStop -- onDestroy

* visible lifetime

> ¿ÉÊÓÉúÃüÖÜÆÚ £º onStart() -- onResume -- onPause -- onStop

* foreground lifetime

> ǰ̨ÉúÃüÖÜÆÚ£º onResume -- onPause

Õý³£µÄÉúÃüÖÜÆÚ

Ò»¸öAPP´ò¿ªµ½Í˳ö

´ò¿ª×îС»¯,---»½ÐÑ-->>Í˳ö

/**
* ActivityÉúÃüÖÜÆÚ
*/
public class MainActivity extends AppCompatActivity {

private static final String TAG = "MainActivity";
* ³õʼ»¯
* @param savedInstanceState
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Log.i(TAG, "======onCreate=======");

}
½çÃæ¿É¼ûʱִÐÐ

@Override
protected void onStart() {
super.onStart();
Log.i(TAG, "======onStart=======");
}

/*
½çÃæ×îС»¯ºó,ÔÙ´ò¿ªÊ±Ö´ÐÐ
*/
@Override
protected void onResume() {
super.onResume();
Log.i(TAG, "======onResume=======");
}

/*
½çÃæ×îС»¯
*/
@Override
protected void onPause() {
super.onPause();
Log.i(TAG, "======onPause=======");
}

/*
½çÃæ²»¿É¼û
*/
@Override
protected void onStop() {
super.onStop();
Log.i(TAG, "======onStop=======");
}
/**
* Í˳öActivityÀïÖ´ÐÐ
*/
@Override
protected void onDestroy() {
super.onDestroy();
Log.i(TAG, "======onDestroy=======");
}
}

7ºáÊúÆÁÇл»£º

1. Ö±½Ó¹æ¶¨ÁËÊÇʲô·½ÏòÏÔʾ

android:screenOrientation="landscape" |portrait

2. ²»Ö¸¶¨·½Ïò£¬ºáÆÁ¾ÍºáÆÁÏÔʾ£¬ÊúÆÁ¾ÍÊúÆÁÏÔʾ

android:configChanges="orientation|screenSize|keyboardHidden"

8ÈÎÎñºÍÕ»

* task

> Ò»¸öÓ¦ÓóÌÐò¿ÉÒÔÓµÓжà¸ö½çÃæ£¬Ò»¸ö½çÃæ¾Í¿ÉÒÔ¿´³ÉÊÇÓëÓû§½»»¥µÄÈÎÎñ task , ΪÁË·½±ã¹ÜÀí£¬ËùÒÔandroid¾ÍʹÓÃÒ»¸öÕ»À´¼¯ÖйÜÀíËûÃÇÕâЩÈÎÎñ £¬ Èç¹ûÒ»¸öÓ¦ÓóÌÐòµÄËùÓÐÕ»¶¼ÒѾ­Çå¿ÕÁË£¬ÄÇôÕâ¸öÓ¦ÓóÌÐòÒ²¾ÍÍêÈ«Í˳öÁË £¬ Ò»¸öÓ¦ÓóÌÐò¿ÉÒÔÓµÓжà¸öÈÎÎñÕ»

* stack

> Õ» £¬ ÊÇÒ»ÖÖÊý¾Ý½á¹¹ ×ñÑ­µÄÊǺó½øÏȳö£¬ ¶ÓÁÐ £¨Queue £© £¬ÏȽøÏȳö

9.ActivityÆô¶¯Ä£Ê½

* standard

> ÕâÊÇĬÈÏµÄÆô¶¯Ä£Ê½£¬£º Æô¶¯¶àÉÙ´ÎÕâ¸ö½çÃæ£¬¾Í»áÓжàÉÙ¸öÕâ¸ö½çÃæÊµÀý±»Ñ¹ÈëÕ»ÖÐ

* singleTop

> µ¥Ò»¶¥²¿Ä£Ê½£ºÈç¹ûÒ»¸ö½çÃæµÄʵÀýÒѾ­´æÔÚÕ»¶¥£¬ÄÇô¾Ã²»»áÔÙ¼ÌÐø´´½¨Õâ¸ö½çÃæµÄʵÀý£¬¶øÊǼÌÐøÊ¹ÓÃÕâ¸öʵÀý¡£¡¡Ö»Òª²»ÊǶ¥²¿£¬¾ÍÓëĬÈϵÄģʽһÑù¡£

> ³¡¾°£º ΪÁ˱ÜÃâ³öÏÖÒ»Ð©Ææ¹ÖµÄÏÖÏó£¬ÎªÁ˱ÜÃâÈÃ×Ô¼ºÆô¶¯×Ô¼º ¶ÌÐűàд½çÃæ*

* singleTask

> µ¥Ò»ÈÎÎñģʽ£ºÈç¹ûÒ»¸ö½çÃæµÄʵÀýÒѾ­´æÔÚÕ»ÖУ¬ÄÇôÔÙ´ÎÆô¶¯¾Í²»»á¼ÌÐø´´½¨ÐµÄʵÀý£¬¶øÊǼÌÐø¸´ÓÃËü£¬²¢ÇÒ°ÑËüÓëÕ»¶¥Ö®¼äµÄÆäËûʵÀýÈ«²¿ÒƳýµô¡£

> ³¡¾°£º ΪÁ˼õÇá×ÊÔ´µÄÏûºÄ£¬ÔÚÕ»ÖÐÖµ´´½¨Ò»´ÎʵÀý£¬ ±ÈÈ磺 ä¯ÀÀÆ÷µÄ½çÃæ

* singleInstance

> È«¾ÖΨһģʽ£º ÎÞÂÛ´´½¨¶àÉٴζ¼Ö»ÓÐÒ»¸öʵÀý£¬²¢ÇÒÕâ¸öʵÀý·ÅÔÚÒ»¸ö¶ÀÁ¢µÄÕ»ÖУ¬ÀïÃæÓÐÇÒÖ»ÄÜÓÐËü×Ô¼ºÒ»¸öʵÀý

> ³¡¾°£º ΪÁ˼õÇá×ÊÔ´µÄÏûºÄ£¬ÔÚÕ»ÖÐÖµ´´½¨Ò»´ÎʵÀý ±ÈÈ磺 ͨ»°½çÃæ»òÕß½ô¼±Í¨»°½çÃæ

   
2093 ´Îä¯ÀÀ       27
 
Ïà¹ØÎÄÕÂ

ÊÖ»úÈí¼þ²âÊÔÓÃÀýÉè¼ÆÊµ¼ù
ÊÖ»ú¿Í»§¶ËUI²âÊÔ·ÖÎö
iPhoneÏûÏ¢ÍÆËÍ»úÖÆÊµÏÖÓë̽ÌÖ
AndroidÊÖ»ú¿ª·¢£¨Ò»£©
 
Ïà¹ØÎĵµ

Android_UI¹Ù·½Éè¼Æ½Ì³Ì
ÊÖ»ú¿ª·¢Æ½Ì¨½éÉÜ
androidÅÄÕÕ¼°ÉÏ´«¹¦ÄÜ
Android½²ÒåÖÇÄÜÊÖ»ú¿ª·¢
Ïà¹Ø¿Î³Ì

Android¸ß¼¶Òƶ¯Ó¦ÓóÌÐò
Androidϵͳ¿ª·¢
AndroidÓ¦Óÿª·¢
ÊÖ»úÈí¼þ²âÊÔ
×îл¼Æ»®
DeepSeek´óÄ£ÐÍÓ¦Óÿª·¢ 6-12[ÏÃÃÅ]
È˹¤ÖÇÄÜ.»úÆ÷ѧϰTensorFlow 6-22[Ö±²¥]
»ùÓÚ UML ºÍEA½øÐзÖÎöÉè¼Æ 6-30[±±¾©]
ǶÈëʽÈí¼þ¼Ü¹¹-¸ß¼¶Êµ¼ù 7-9[±±¾©]
Óû§ÌåÑé¡¢Ò×ÓÃÐÔ²âÊÔÓëÆÀ¹À 7-25[Î÷°²]
ͼÊý¾Ý¿âÓë֪ʶͼÆ× 8-23[±±¾©]

androidÈË»ú½çÃæÖ¸ÄÏ
AndroidÊÖ»ú¿ª·¢£¨Ò»£©
AndroidÊÖ»ú¿ª·¢£¨¶þ£©
AndroidÊÖ»ú¿ª·¢£¨Èý£©
AndroidÊÖ»ú¿ª·¢£¨ËÄ£©
iPhoneÏûÏ¢ÍÆËÍ»úÖÆÊµÏÖ̽ÌÖ
ÊÖ»úÈí¼þ²âÊÔÓÃÀýÉè¼ÆÊµ¼ù
ÊÖ»ú¿Í»§¶ËUI²âÊÔ·ÖÎö
ÊÖ»úÈí¼þ×Ô¶¯»¯²âÊÔÑо¿±¨¸æ

Android¸ß¼¶Òƶ¯Ó¦ÓóÌÐò
AndroidÓ¦Óÿª·¢
Androidϵͳ¿ª·¢
ÊÖ»úÈí¼þ²âÊÔ
ǶÈëʽÈí¼þ²âÊÔ
AndroidÈí¡¢Ó²¡¢ÔÆÕûºÏ

ÁìÏÈIT¹«Ë¾ android¿ª·¢Æ½Ì¨×î¼Ñʵ¼ù
±±¾© Android¿ª·¢¼¼Êõ½ø½×
ijÐÂÄÜÔ´ÁìÓòÆóÒµ Android¿ª·¢¼¼Êõ
ijº½Ì칫˾ Android¡¢IOSÓ¦ÓÃÈí¼þ¿ª·¢
°¢¶û¿¨ÌØ LinuxÄÚºËÇý¶¯
°¬Ä¬Éú ǶÈëʽÈí¼þ¼Ü¹¹Éè¼Æ
Î÷ÃÅ×Ó Ç¶Èëʽ¼Ü¹¹Éè¼Æ