Programatically change main(launch) activity in android
My Scenario
I'm developing web socket based application on android. Application contains global WebSocketConnection
. According to the status of the web socket connection, I need to change the launch activity(When user click on launch icon two different activities need to be start, according to the web socket connection status). Following are the two scenarios.
- If web socket already connected - Start
HomeActivty
- If web socket not connected - Start
SplashActivity
Implementation
- First I have created
LaunchActivity
with no UI and set it as main(launch) activity. In order to create an activity without UI we can useTheme.NoDisplay
-
LaunchActivity
determines which activity to display according to the websocket connection status. Following is the implementation ofLaunchActivity
https://github.com/erangaeb/dev-notes/blob/master/android-launch/LaunchActivity.java
- Following is the part of my
AndroidManifest.xml
which defines activities and their themes
https://github.com/erangaeb/dev-notes/blob/master/android-launch/AndroidManifest.xml
Written by eranga bandara
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Android
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#