Android 簡(jiǎn)單跳轉(zhuǎn)頁(yè)面工具的實(shí)例詳解
事情起源
activity 或者 fragment 每次跳轉(zhuǎn)傳值的時(shí)候,你是不是都很厭煩那種,參數(shù)傳遞。
那么如果數(shù)據(jù)極其多的情況下,你的代碼將苦不堪言,即使在很好的設(shè)計(jì)下,也會(huì)很難受。那么今天我給大家推薦一個(gè)工具
和咱原生跳轉(zhuǎn)進(jìn)行比較
比較:
1.跳轉(zhuǎn)方式比較
Intenti=new Intent(this,MainActivity.class); startActivity(i);
vs
ApMainActivity.getInstance().start(this);
//發(fā)送 Intenti=new Intent(this,MainActivity.class); Bundle bundle = new Bundle(); bundle.putInt("message", "123"); i.putExtra("Bundle", bundle); startActivity(i); //接收 String s=bundle.getString("message","");
vs
//發(fā)送 ApMainActivity.getInstance().setMessage("123").start(this); //接收 AutoJ.inject(this);
AutoPage
github地址 https://github.com/smartbackme/AutoPage
如果覺(jué)得不錯(cuò) github 給個(gè)星
Android 容易的跳轉(zhuǎn)工具
注意事項(xiàng):必須有如下兩個(gè)要求 androidxkotlin & java
#########使用#########
project : build.gradle 項(xiàng)目的gradle配置
buildscript { repositories { maven { url 'https://dl.bintray.com/297165331/AutoPage'} }
在你的每個(gè)需要做容易跳轉(zhuǎn)的模塊添加如下配置
你的項(xiàng)目必須要支持 kapt
kotlin kapt
apply plugin: 'kotlin-kapt' implementation 'com.kangaroo:autopage:1.0.2' kapt 'com.kangaroo:autopage-processor:1.0.2'
重點(diǎn)
@AutoPage 只能在字段或者類(lèi)上標(biāo)注Ap 作為前綴,為你快速跳轉(zhuǎn)
kotlin:
字段必須標(biāo)注 @JvmField 和 @AutoPageonCreate 中 在你的需要跳轉(zhuǎn)的頁(yè)面加入 AutoJ.inject(this)
java:
字段必須標(biāo)注 @AutoPageonCreate 中 在你的需要跳轉(zhuǎn)的頁(yè)面加入 AutoJ.inject(this)
######### Activity 中使用#########
例1
簡(jiǎn)單的跳轉(zhuǎn)
@AutoPage class SimpleJump1Activity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_simple_jump1) } }
之后調(diào)用
ApSimpleJump1Activity.getInstance().start(this)
例2
簡(jiǎn)單的跳轉(zhuǎn)并且?guī)?shù)
class MainActivity2 : AppCompatActivity() { @AutoPage @JvmField var message:String? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main2) AutoJ.inject(this) findViewById<TextView>(R.id.text).text = message } }
之后調(diào)用
ApMainActivity2.getInstance().setMessage("123").start(this)
例3:
跳轉(zhuǎn)帶有result
@AutoPage class SimpleJumpResultActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_simple_jump_result) } override fun onBackPressed() { var intent = Intent() intent.putExtra("message","123") setResult(RESULT_OK,intent) super.onBackPressed() } }
之后調(diào)用
ApSimpleJumpResultActivity.getInstance().requestCode(1).start(this)
####### 在 fragment 中使用 #########
class FragmentSimpleFragment : Fragment() { @AutoPage @JvmField var message:String? = null companion object { fun newInstance() = FragmentSimpleFragment() } private lateinit var viewModel: SimpleViewModel override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { return inflater.inflate(R.layout.simple_fragment, container, false) } override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) AutoJ.inject(this) viewModel = ViewModelProvider(this).get(SimpleViewModel::class.java) view?.findViewById<TextView>(R.id.message)?.text = message } }
之后調(diào)用
ApFragmentSimpleFragment.getInstance().setMessage("134").build()
到此這篇關(guān)于Android 簡(jiǎn)單跳轉(zhuǎn)頁(yè)面工具的文章就介紹到這了,更多相關(guān)Android跳轉(zhuǎn)頁(yè)面工具內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android實(shí)現(xiàn)QQ登錄界面遇到問(wèn)題及解決方法
本文給大家介紹android仿qq登錄界面的實(shí)現(xiàn)代碼,在實(shí)現(xiàn)此功能過(guò)程中遇到各種問(wèn)題,但是最終都順利解決,如果大家對(duì)android qq登錄界面實(shí)現(xiàn)方法感興趣的朋友一起學(xué)習(xí)吧2016-09-09Android檢測(cè)url地址是否可達(dá)的兩種方法
今天小編就為大家分享一篇Android檢測(cè)url地址是否可達(dá)的兩種方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-01-01Android listView 繪制表格實(shí)例詳解
這篇文章主要介紹了Android listView 繪制表格實(shí)例詳解的相關(guān)資料,這里附有實(shí)例代碼及實(shí)現(xiàn)效果圖,利用listView 繪制表格提供實(shí)現(xiàn)思路,需要的朋友可以參考下2017-01-01Flutter?StreamBuilder實(shí)現(xiàn)局部刷新實(shí)例詳解
這篇文章主要為大家介紹了Flutter?StreamBuilder實(shí)現(xiàn)局部刷新實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08Android 中 Fragment 嵌套 Fragment使用存在的bug附完美解決方案
本文從兩個(gè)方面淺析Android 中 Fragment 嵌套 Fragment使用存在的bug問(wèn)題,原因找到就可以完美的解決了,對(duì)fragment嵌套fragment使用相關(guān)知識(shí)感興趣的朋友一起看看吧2016-08-08Android中使用Matrix控制圖形變換和制作倒影效果的方法
這篇文章主要介紹了Android中使用Matrix控制圖形變換和制作倒影效果的方法,用Matrix來(lái)作矩陣變化十分強(qiáng)大,文中的制作倒影的例子便是一個(gè)十分巧妙的運(yùn)用,需要的朋友可以參考下2016-04-04Android?Studio支持安卓手機(jī)投屏功能詳解
這篇文章主要給大家介紹了關(guān)于Android?Studio支持安卓手機(jī)投屏功能的相關(guān)資料,文中通過(guò)圖文介紹的非常詳細(xì),對(duì)有需要的朋友具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2023-01-01Android Studio生成函數(shù)注釋的實(shí)現(xiàn)方法
這篇文章主要介紹了Android Studio生成函數(shù)注釋的實(shí)現(xiàn)方法的相關(guān)資料,希望通過(guò)本文大家能夠?qū)崿F(xiàn)這樣的功能,需要的朋友可以參考下2017-09-09詳解Android中ListView實(shí)現(xiàn)圖文并列并且自定義分割線(完善仿微信APP)
本篇文章主要介紹了Android中ListView實(shí)現(xiàn)圖文并列并且自定義分割線(完善仿微信APP),具有一定的參考價(jià)值,有興趣的可以了解一下。2016-12-12