| Start | ||||||||
|---|---|---|---|---|---|---|---|---|
| Activity launchMode Launch mode defines the behaviour of new or existing activity in the task.
It should be defined in android manifest in Standard:Default value. If this mode set, new activity will always be created for each new intent. So it's possible to get many activities of same type. New activity will be placed on the top of the task. There is some difference for different android version: if activity is starting from another application, on androids <= 4.4 it will be placed on same task as starter application, but on >= 5.0 new task will be created. SingleTop:This mode is almost the same as SingleTask:Activity with this launch mode can have only one instance in the system. New task for activity will be created, if it doesn't exist. Otherwise, task with activity will be moved to front and SingleInstance:This mode is similar to |
||||||||
| Exclude an activity from back-stack history Let there be Activity The simplest solution is to set the attribute This same behavior is also possible from code if Typical usage of |
||||||||
| Android Activity LifeCycle Explained Assume an application with a MainActivity which can call the Next Activity using a button click. and When app is first created When screen sleeps Case1:
When Next Activity is called from Main Activity When Returning back to the Main Activity from Next Activity using back button Case2:
When Activity is partially obscured (When overview button is pressed) or When app goes to background and another app completely obscures it Case3:
When an activity is called to fulfill implicit intent and user has make a selection. For eg., when share button is pressed and user has to select an app from the list of applications shown The activity is visible but not active now. When the selection is done and app is active Case4: onCreate and onDestroy will be called utmost once each time the application is run. But the onPause, onStop, onRestart, onStart, onResume maybe called many times during the lifecycle. |
||||||||
| End Application with exclude from Recents First define an ExitActivity in the AndroidManifest.xml Afterwards the ExitActivity-class |
||||||||
| Presenting UI with setContentView Activity class takes care of creating a window for you in which you can place your UI with
When ExamplesSet content from resource file:Set it as content in activity: Set content to an explicit view: |
||||||||
| Clear your current Activity stack and launch a new Activity If you want to clear your current Activity stack and launch a new Activity (for example, logging out of the app and launching a log in Activity), there appears to be two approaches. 1. Target (API >= 16) Calling 2. Target (11 <= API < 16) |
||||||||
| Up Navigation for Activities Up navigation is done in android by adding How is it done? Now when i will click on the arrow inside the toolbar of HomeActivity it will take me back to the parent activity. Java Code Here i will write the appropriate java code required for this functionality. If you run this code you will see when you press back button it will take you back to MainActivity. For futher understanding of Up Navigation i would recommend reading docs (opens new window) You can more customize this behaviour upon your needs by overriding Simple Hack This is simple hack which is mostly used to navigate to parent activity if parent is in backstack. By calling SyntaxParameters
RemarksAn Activity (opens new window) is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows. |
Read Article
https://develop.horje.com/learn/1434/reference