Last Updated: October 18, 2020
· itseranga

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.

  1. If web socket already connected - Start HomeActivty
  2. If web socket not connected - Start SplashActivity


  • 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 use Theme.NoDisplay


  • LaunchActivity determines which activity to display according to the websocket connection status. Following is the implementation of LaunchActivity

  • Following is the part of my AndroidManifest.xml which defines activities and their themes