Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOSエンジニアが悩んだUpボタンについて / 2017 potatotips 45 Up B...

M"e
November 28, 2017

iOSエンジニアが悩んだUpボタンについて / 2017 potatotips 45 Up Button

M"e

November 28, 2017
Tweet

More Decks by M"e

Other Decks in Programming

Transcript

  1. © 2017 VASILY,Inc. class ChildActivity : AppCompatActivity(), ItemDetailEventHandler { private

    lateinit var fromActivity: FromActivity private const val FROM_ACTIVITY = "from_activity" enum class FromActivity { HOME, SEARCH_RESULT, ɾɾɾ } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) fromActivity = intent.getSerializableExtra(FROM_ACTIVITY) as FromActivity } override fun onOptionsItemSelected(item: MenuItem?): Boolean { when (item?.itemId) { android.R.id.home -> { val intent = createIntent(fromActivity) intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP navigateUpTo(intent) return true } else -> return false } } private fun createIntent(fromActivity: FromActivity): Intent { return when (fromActivity) { FromActivity.HOME -> Intent(this, HomeActivity::class.java) FromActivity.SEARCH_RESULT -> Intent(this, SearchItemResultActivity::class.java) ɾɾɾ } } }