Free Android app covering all aspects of addiction, including prevention and treatment

App remodelling: From Activities to fragments

Converting Android activities to fragments activityToFragment icon

Got an app using activities that you want to convert to using fragments?

We’ll show you how easy it is to convert activity apps to fragment apps. It’s no big deal.

Android: Launching activities

Launch Mode

Android launchMode launchMode icon

The launch mode specifies how a new activity should be associated with the current task.

Before trying to make sense of this, let’s first have a look at:

  • the Back Stack
  • and Tasks

Passing Serialized objects between activities

Android Serializable objects icon

You can pass primitive data, like integers, strings, booleans and array lists between activities.

You can also pass Serialized objects between activities. We’ll show you how.

Android Activities

Getting active: all about Activities

Android Activity icon

Activities are application components that we, mostly, see as the screen. It displays images, text, buttons, etc. that we interact with. Some activities don’t display anything.

Apps usually have a number of activities. One is seen as the main activity. This is the first screen we see when the app starts.

How to save your Activity’s Instance State

What is Instance State?

ConfigChange iconThe data that is saved by the system to restore the previous state of an activity is called the Instance State. This data is saved as a collection of key/value pairs in a Bundle object.

Same as it ever was: Persisting the Activity state

ActivityState iconWhen an activity is paused or stopped, its state is kept in memory. When the activity resumes, it is restored from memory.

When the activity is destroyed, it loses all information about its state. When the activity is restarted, it is created from scratch. It is a new activity.

The Activity Lifecycle

Round and round we go:The Activity Lifecycle

Android activity lifecycle tutorialEach app runs in its own process and contains one or more activities.

The Android run time manages these processes and decides which app to kill if it needs resources.

An app’s priority helps determine if the run time will kill it and its running activities.

The app’s priority is influenced by its highest priority activity.

If the Android’s memory manager needs to free up memory, it looks at the activity stack to determine the priority of the activities and which ones can be closed.

Start an activity for a result

Start me up: Starting an activity to get a result

Starting activity for result - result iconSometimes, you may need to get data from another activity. That activity could be in your app or in another app.

You could use startActivityForResult() to get that data for you.

Exchanging primitive data between activities

dataXchange iconYou may want to pass data from one activity to another.

It all depends on the type of data

You could put the data in a central point and then access it from anywhere.

Here are some of the ways to do that: