A ctivity
4个状态
runPausStopeKilled
onstart
onReSU作文题材me
onRestart
onPause
onStop
onDestroy
视频题材oidman学生题材ifestxml%0a=”” ctivity%0a=”” ctivitya=”” seconda=”” second_layout影视题材_xml%0a=””>从界面1通报数据到界面2
创立second_layoutxml文件;
创立SecondA ct类文件,承继自Activity
AndroidManifest.xml做下注册;
第一个界面界说数据,通报到第二个界面,借助于Bundl工具;
第二个界面承受数据;
从界面2回传数据到界面1这个我做了下简化;
创立second_layoutxml文件;
创立SecondA ct类文件,承继自Activity
AndroidManifest.xml做下注册;
第一个界面界说数据,通报到第二个界面,借助于Bundl工具;
第二个界面承受数据;
从界面2回传数据到界面1这个我做了下简化;
这里拔出代码片` 视频题材operator">< ?xmlversion = "1.0"encoding = "utf-8" ? > < LinearLayoutandroid :layout_width = "wrap_content"a作文题材ndroid :layout_height = "wrap_content"xmlns :android = "http://schemas.android.短片题材com/apk/res/四季题材android" > < EditTextandroid :layout_width = "300dp"android :layout_height = "wrap_content"android :id = "@+id/etInfo视频题材" / > < Buttonandroid :layout_width = "wrap_content"android :id = "@+id/btn01"android :layout_height = "wrap_content"android :text = "挪用第二个" / > < / LinearLayout >`
复制短片题材
2.主界面对应的java文件
@OverridprotectvoidonCreatBundlsavedInstanceSt{super.onCrsavedInstanceSt;setContentView四季题材R.layout.activity_main;//--------------------------官方声明工具;EditTextetInfo=EditTextfindViewByIdR.i小说题材d.etInfo;Buttonbtn01=ButtonfindViewByIdR.id.btn01;//事情监听;btn01.s瀑布题材etOnClickListennewView.OnClickListen{@OverridpublicvoidonClickViewv{Intentintent=newIntentMainA ctivity.this,SecondA ctivity.class;//*************************//通报数据到第二个界面;Stringinfo=EditTextfindViewByIdR.id.etInfo.getText.toStr;Bundlbundle=newBundl;//也可以把它当做javaMap接影视题材纳key-valu花影视题材样传值;bundle.putStr"info",info;//将bundl工具通报到intent外面;intent.putExtrabundl;//******************************startA ctivintent;//开端做回传了;startA ctivityForResultintent,100;}};}//第二个针对回传数据的办法;@OverridprotectvoidonA ctivityResultintrequestCode,intresultCode,@NullablIntentdata{super.onA ctivityResultrequestCode,resultCode,data;//1.恳求码2前往码;3.回传数据;ifrequestCode==100&&resultCode==A ppCompatA ctivity.RESULT_OK{Stringdt=data.getExtra.getStr"eText1";//这个才是前往的数据值;EditTexteText1=EditTextfindViewByIdR.id.etInfo;eText1.setText"回传数据:"+dt;}}
}
复制
3.第二个界面文件xml
< ?xmlversion = "1.0"encoding = "utf-8" ? > < LinearLayoutxmlns :android = "http://schemas.android.com/apk/res/android"android :layout_width = "match_parent"android :orientation = "vertical"android :layout_height = "match_parent" > < EditTextandroid :layout_width = "300dp"android :layout_height = "wrap_content"android :id = "@+id/etInfo2" / > < Buttonandroid :layout_width = "wrap_content"android :id = "@+id/btn02"android :layout_height = "wrap_content"android :text = "界面2按钮,回传数据" / > < / LinearLayout >
复制
4.第二个界面的java文件
package com .aaa .activitydemo01 ; import android .app . A ctivity ; import android .content . Intent ; import android .os . Bundle ; import android .view . View ; import android .widget . Button ; import android .widget . EditText ; import android .widget . Toast ; import androidx .annotation . Nullable ; public class SecondA ctivity extends A ctivity { @Override protected void onCreate @Nullable BundlesavedInstanceState { super . onCreate savedInstanceState ; setContentView R .layout .second_layout ; Intentintent = this . getIntent ; Bundlebundle =intent . getExtras ; Stringinfo =bundle . getString "info" ; EditText findViewById R .id .etInfo2 . setText "收到界面1" +info ; Buttonbtn02 = Button findViewById R .id .btn02 ;btn02 . setOnClickListener new View .OnClickListener { @Override public void onClick Viewv { IntentintentData = new Intent ; StringeditText1 = EditText findViewById R .id .etInfo2 . getText . toString ; System .out . println editText1 ;intentData . putExtra "eText1" ,editText1 ; setResult A ctivity .RESULT_OK ,intentData ; finish ; } } ; } }
复制
5.切忌不要忘了信息综合设置文件:
< ?xmlversion = "1.0"encoding = "utf-8" ? > <manifestxmlns :android = "http://schemas.android.com/apk/res/android" package = "com.aaa.activitydemo01" > <applandroid :allowBackup = "true"android :icon = "@mipmap/ic_launcher"android :label = "@string/app_n小说题材ame"android :roundIcon = "@mipmap/ic_launcher_round"android :supportsRtl = "true"android :theme = "@style/Theme.A ctivitydemo01" > <actandroid :name = ".MainA ctivity"android :exported = "true" > <intent -filter > <actandroid :name = "android.intent.action.MA IN" / > <categoriandroid :name = "android.intent.category.LA UNCHER" / > < /intent -filter > < /activity > <actandroid :name = ".SecondA ctivity"android :label = "第二个activity" > < /activity > < /application > < /manifest >
复制
6.好效果图:
原文链接:https://blog.csdn.net/zhangchen124/article/details/123964685?ops_request_misc=%257B%2522request%255Fid%2522%253A %2522166856496116782429764990%2522%252C%2522scm%2522%253A %252220140713.130102334.pc%255Fblog.%2522%257D&request_id=166856496116782429764990&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-21-123964685-null-null.nonecase&utm_term=%E9%A 2%98%E6%9D%90
未经允许不得转载:题材网 » Activiti完成界面间传值和数据回传案例