Skip to end of metadata
Go to start of metadata

AppCompatActivity provides a single view container for your application. Unlike Android classic development, the purpose of AppCompatActivity is solely for view container. This means that you need to create a Fragment that will be injected to the Activity as your view content. Crosslight Android Material provides you with various type of fragments such as RecyclerViewFragment, MapFragment, MasterDetailFragment, etc that you can use to define your view easily.

To learn more about the concept and roles in Crosslight Material Views, see Defining Android Material Views.

On this page:

Using AppCompatActivity as Main Activity

In Crosslight Android apps, you typically need at least one Activity class for the main activity that represents the first view of your application. In Crosslight, this Activity is the one you set as root view model in AppService.cs inside the Core project as follows.

Here's the code for the Activity.

Customizing Modal Activity

In addition to main Activity, you can use Activity to represent a modal navigation, where the previous view state will be suspended while keeping the view state intact. Since the pattern is quite straightforward, Crosslight Android Material provides a built-in modal Activity so that you do not need to create Activity for each modal navigation in your application. You can simply use navigation service to navigate to a ViewModel that uses Fragment for its view.

The following code shows you how to perform modal navigation using the built-in navigation service and how to define the target fragment for your modal navigation.

Here's an example of the target Fragment.

When the navigation service is executed it will open a new modal activity with ItemEditFragment as its content. This is done automatically. If you want to customize this modal Activity, let's say you want to customize the theme for this modal Activity, you can do this by declaring an AppCompatActivity with the same associated target ViewModel as follows.

Samples

To see the AppCompatActivity in action, check out these samples: