直接上代碼吧与倡,只是自己做記錄方便以后查閱
/**啟動Activity*/
inline fun <reified T : Activity> Context.onStart() {
startActivity(Intent(this, T::class.java))
}
/**啟動Activity*/
inline fun <reified T : Activity> Context.onStart(mKey: String, mBundle: Bundle?) {
val mIntent = Intent(this, T::class.java)
mIntent.putExtra(mKey, mBundle)
startActivity(mIntent)
}
/**啟動Activity*/
inline fun <reified T : Activity> Context.onStart(vararg pair: Pair<String, String>?) {
val mIntent = Intent(this, T::class.java)
pair?.let {
pair.forEach {
mIntent.putExtra(it!!.first, it!!.second)
}
}
startActivity(mIntent)
}
/**啟動Activity*/
inline fun <reified T : Activity> Activity.onStart() {
startActivity(Intent(this, T::class.java))
}
/**啟動Activity*/
inline fun <reified T : Activity> Activity.onStart(mKey: String, mBundle: Bundle?) {
val mIntent = Intent(this, T::class.java)
mIntent.putExtra(mKey, mBundle)
startActivity(mIntent)
}
/**啟動Activity*/
inline fun <reified T : Activity> Activity.onStart(vararg pair: Pair<String, String>?) {
val mIntent = Intent(this, T::class.java)
pair?.let {
pair.forEach {
mIntent.putExtra(it!!.first, it!!.second)
}
}
startActivity(mIntent)
}
/**啟動Activity*/
inline fun <reified T : Activity> Activity.onStartResult(requestCode: Int) {
startActivityForResult(Intent(this, T::class.java), requestCode, null)
}
/**啟動Activity*/
inline fun <reified T : Activity> Activity.onStartResult(requestCode: Int, mBundle: Bundle?) {
startActivityForResult(Intent(this, T::class.java), requestCode, mBundle)
}
/**啟動Activity*/
inline fun <reified T : Activity> Activity.onStartResult(requestCode: Int, vararg pair: Pair<String, String>) {
val mIntent = Intent(this, T::class.java)
val mBundle = Bundle()
pair?.let {
pair.forEach {
mBundle.putString(it!!.first, it!!.second)
}
}
startActivityForResult(mIntent, requestCode, mBundle)
}