# How to use driver.currentActivity() with AppiumDriver?

**URL:** <https://discuss.appium.io/t/how-to-use-driver-currentactivity-with-appiumdriver/8766>\
**Category:** Support\
**Created:** [February 25, 2016, 10:38am UTC](https://discuss.appium.io/t/how-to-use-driver-currentactivity-with-appiumdriver/8766 "2016-02-25T10:38:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaychosen](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@shaychosen](https://discuss.appium.io/u/shaychosen)\
**Post date:** [February 25, 2016, 10:38am UTC](https://discuss.appium.io/t/how-to-use-driver-currentactivity-with-appiumdriver/8766/1 "2016-02-25T10:38:33Z")

</div>

Hi,  
I’m working on the latest java client 3.3.0 and I see that I can use driver.currentActivity() only when the main driver set to AndroidDriver. As I’m testing IOS and Android in the same project, I need to use AppiumDriver. How I can still work with driver.currentActivity()?  
can I use somthing else?  
please advice.  
thanks

---

<div class="post-metadata">

**Author:** ![afwang](https://discuss.appium.io/user_avatar/discuss.appium.io/afwang/32/2419_2.png) [@afwang](https://discuss.appium.io/u/afwang)\
**Post date:** [February 25, 2016, 10:08pm UTC](https://discuss.appium.io/t/how-to-use-driver-currentactivity-with-appiumdriver/8766/2 "2016-02-25T22:08:24Z")

</div>

A quick way to solve this is to cast your driver reference. In your Android-specific code sections, if you know the driver object type will be an AndroidDriver, you can cast the driver reference from the AppiumDriver type to an AndroidDriver type. Be sure that you actually are working on an AndroidDriver in the Android-specific sections, however. If you’re wrong, you will run into ClassCastExceptions, which means you should really double-check your code!

---

<div class="post-metadata">

**Author:** ![shaychosen](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@shaychosen](https://discuss.appium.io/u/shaychosen)\
**Post date:** [February 28, 2016, 3:23pm UTC](https://discuss.appium.io/t/how-to-use-driver-currentactivity-with-appiumdriver/8766/3 "2016-02-28T15:23:17Z")

</div>

I found this solution and it worked:  
`String activity = ((AndroidDriver<MobileElement>) driver).currentActivity();`  
Thanks!

---

<div class="post-metadata">

**Author:** ![VikramVI](https://discuss.appium.io/user_avatar/discuss.appium.io/vikramvi/32/116_2.png) [@VikramVI](https://discuss.appium.io/u/VikramVI)\
**Post date:** [January 24, 2017, 4:17pm UTC](https://discuss.appium.io/t/how-to-use-driver-currentactivity-with-appiumdriver/8766/4 "2017-01-24T16:17:57Z")

</div>

@shaychosen your solution didn’t work in my case, getting error

java.lang.ClassCastException: io.appium.java\_client.ios.IOSDriver cannot be cast to io.appium.java\_client.android.AndroidDriver

can you please share sample code which uses driver across both android and iOS native apps ?

> <https://github.com/appium/java-client/issues/87>

interesting discussion on this topic for reference purpose

---

<div class="post-metadata">

**Author:** ![Bala\_Kumar](https://discuss.appium.io/user_avatar/discuss.appium.io/bala_kumar/32/4596_2.png) [@Bala\_Kumar](https://discuss.appium.io/u/Bala_Kumar)\
**Post date:** [April 30, 2021, 10:32am UTC](https://discuss.appium.io/t/how-to-use-driver-currentactivity-with-appiumdriver/8766/5 "2021-04-30T10:32:51Z")

</div>

@VikramVI  
Have you found any solution to identify current iOS screen?
