日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Activity与Intent

發(fā)布時(shí)間:2024/1/17 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Activity与Intent 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

android5個(gè)進(jìn)程等級(jí)

1.Activity process(critical priority):活動(dòng)進(jìn)程(前臺(tái)進(jìn)程)

2.Visible process(High priority):可見進(jìn)程

3.Started Service process(High priority)

4.Background process(Low priority)

5.Empty process(Low priority)

退出進(jìn)程:

System.exit(8);//系統(tǒng)進(jìn)程正常退出

Process.killProcess(Process.myPid);//類似于垃圾回收

Activity創(chuàng)建過程:

1.建立Activity類及定義屬性及內(nèi)部方法;

2.注冊(cè)Activity到manifast中;

3.在啟動(dòng)中使用onCreat()實(shí)現(xiàn)業(yè)務(wù):

  (1)界面定義

  (2)setContentView()加載頁面;

//將layout壓縮成View View view=this.getLayoutInflater().inflate(R.layout.activity_activity_demo, null);

Intent:

Intent有兩種:Explicit intents(明確的意圖);Implicit intents?(含蓄的意圖)

Explicit?intents:通過組件名啟動(dòng)

Implicit intents:通過匹配manifest file中的Intent filter來啟動(dòng)組件,若匹配結(jié)果僅有一項(xiàng),直接啟動(dòng);若多項(xiàng)匹配,根據(jù)彈出的dialog進(jìn)行選擇

1.Explicit?intents

Intent屬性:Component:啟動(dòng)Explicit intents必不缺少的

//顯示啟動(dòng)Intent,必須指定Intent屬性Component,Component屬性需要指定ComponentName//1.直接創(chuàng)建時(shí)指定Intent intent=new Intent(ActivityDemoActivity.this, ActivityIntentDemo.class);Intent intent=new Intent();//2.通過ComponentName構(gòu)造器來指定;只須指定包名與類名就可以唯一確定組件名ComponentName componentName=new ComponentName("androidstudy.ActivityDemo","androidstudy.ActivityDemo.ActivityIntentDemo");ComponentName componentName=new ComponentName(ActivityDemoActivity.this,ActivityIntentDemo.class);ComponentName componentName=new ComponentName(ActivityDemoActivity.this,"androidstudy.ActivityDemo.ActivityIntentDemo");intent.setComponent(componentName);//3.setClass()與setClassName()指定intent.setClass(ActivityDemoActivity.this, ActivityIntentDemo.class);intent.setClassName(ActivityDemoActivity.this, "androidstudy.ActivityDemo.ActivityIntentDemo");intent.setClassName("androidstudy.ActivityDemo","androidstudy.ActivityDemo.ActivityIntentDemo");startActivity(intent);

返回Intent傳遞參數(shù)是否成功

調(diào)用startActivityForResult(intent, 1234);

intent是傳遞的Intent,1234為RequestResult,成功后回調(diào)函數(shù)protected void onActivityResult(int requestCode, int resultCode, Intent data) ;

在新的Activity 中通過調(diào)用函數(shù)setResult(5678,mIntent);設(shè)置回調(diào)的resultCode與Intent

//調(diào)用Intent的Activity public void demo(View view){ //顯示啟動(dòng)Intent,必須指定Intent屬性Component,Component屬性需要指定ComponentName//1.直接創(chuàng)建時(shí)指定//Intent intent=new Intent(ActivityDemoActivity.this, ActivityIntentDemo.class);intent=new Intent();//2.通過ComponentName構(gòu)造器來指定;只須指定包名與類名就可以唯一確定組件名//ComponentName componentName=new ComponentName("androidstudy.ActivityDemo","androidstudy.ActivityDemo.ActivityIntentDemo");//ComponentName componentName=new ComponentName(ActivityDemoActivity.this,ActivityIntentDemo.class);//ComponentName componentName=new ComponentName(ActivityDemoActivity.this,"androidstudy.ActivityDemo.ActivityIntentDemo");//intent.setComponent(componentName);//3.setClass()與setClassName()指定intent.setClass(ActivityDemoActivity.this, ActivityIntentDemo.class);//intent.setClassName(ActivityDemoActivity.this, "androidstudy.ActivityDemo.ActivityIntentDemo");//intent.setClassName("androidstudy.ActivityDemo","androidstudy.ActivityDemo.ActivityIntentDemo");intent.putExtra("STUDY", "hello 陽光 ");startActivityForResult(intent, 1234);}protected void onActivityResult(int requestCode, int resultCode, Intent data) {if(resultCode==5678){Toast.makeText(ActivityDemoActivity.this, data.getExtras().getString("STUDY"), Toast.LENGTH_LONG).show();System.out.println(intent.getStringExtra("STUDY"));}super.onActivityResult(requestCode, resultCode, data);}; //接收Intent的Activity public void click(View view){mIntent.putExtra("STUDY", "hello moon");//設(shè)置返回值setResult(5678,mIntent);//關(guān)閉此Activityfinish();}

2.Implicit intents

//隱式啟動(dòng)Intent//啟動(dòng)電話Activity,Action:Intent.ACTION_DIAL Intent intent=new Intent();intent.setAction(Intent.ACTION_DIAL);intent.setData(Uri.parse("tel:15169091171"));startActivity(intent);//啟動(dòng)電話Activity,Action:Intent.ACTION_CALLIntent intent=new Intent();intent.setAction(Intent.ACTION_CALL);intent.setData(Uri.parse("tel:15169091171"));startActivity(intent);

通過代碼分析?Action:Intent.ACTION_DIAL與Activity,Action:Intent.ACTION_CALL區(qū)別:

  DIAL啟動(dòng)的Action并不會(huì)直接撥號(hào),需用戶進(jìn)行確然撥號(hào);

  ACTION_CALL啟動(dòng)的Action可直接進(jìn)行撥號(hào),但需要在manifest.xml文件中加上權(quán)限<uses-permission android:name="android.permission.CALL_PHONE"/>

Intent intent=new Intent();intent.setAction("moon.testDemo");intent.setData(Uri.parse("http://www.hao123.com"));startActivity(intent); xml:<activity android:name=".ActivityIntentDemo"><intent-filter><action android:name="moon.testDemo"/><category android:name="android.intent.category.DEFAULT"/><data android:scheme="http"/></intent-filter></activity>

備注:1.雖然Activity中并沒有設(shè)置category屬性,但默認(rèn)設(shè)置屬性為DEFAULT,所以在manifest.xml文件中要添加

<category android:name="android.intent.category.DEFAULT"/>,否則,運(yùn)行會(huì)出現(xiàn)錯(cuò)誤。

2.若 ? ? ? ?SaveInstanceState()函數(shù)會(huì)自動(dòng)保存我們提供android:id的空間

2.狀態(tài)恢復(fù)onRestoreInstanceState()或onCreat():onResume()之前調(diào)用

備注:

1.重構(gòu)onSaveInstanceState()與onRestoreInstanceState()函數(shù)時(shí),需調(diào)用父類函數(shù);

2.onRestoreInstanceState()函數(shù)不一定會(huì)被調(diào)用,一般恢復(fù)函數(shù)使用onCreat();

3.由于onSaveInstanceState()函數(shù)不一定會(huì)被調(diào)用,所以一般存儲(chǔ)短暫的狀態(tài),存儲(chǔ)長(zhǎng)期狀態(tài)一般使用onPause();

ConfigurationChanges

獲取configuration Configuration cfg=getResources().getConfiguration()

?

Activity基類:

FragmentActivity、AccountAuthenticatorActivity(實(shí)現(xiàn)賬戶管理界面)、TabActivity(Tab界面)、ListActivity(列表界面)、LauncherActivity(Activity列表界面)、PreferenceActivity(程序參數(shù)設(shè)置存儲(chǔ)界面)、AliasActivity(別名Activity基類,用于開始別人時(shí)結(jié)束自己)、ExpandableListActivity(可擴(kuò)展列表界面)

?

轉(zhuǎn)載于:https://www.cnblogs.com/Eudora/p/3513663.html

總結(jié)

以上是生活随笔為你收集整理的Activity与Intent的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。