WepsTech
The world of development
Great you are on the right post! Previously I was working on the Java language for developing an android application. I thought to move with new technology in android development. Then I move completely with Kotlin Language for android application development. But somewhere I have found that some keys and syntax has been changed. One of then instanceof. I was trying to find the solution with the instanceof keyword, but in Kotlin nothing is like that to check instance of. So there is a small question in front of every Android developer. which is
Finally I have fond the solution of this question and I am sharing with you people.
fun checkInstanceOFActivityInFragment() { if (activity is MainActivity) { //Main Activity } else if (activity is OTPActivity) { //OTP Activity } }
fun checkInstanceOfFragment(){ val f = supportFragmentManager.findFragmentById(R.id.container) if (f is FragmentOne) { //Fragment One } else if (f is FragmentTwo) { //Fragment Two } }
Awesome This is the example code. You can see one more code for checking instances of fragment.
Appart form these cods you can go through with some tutorials which is mention below.