View all of your Slices in one place

In addition to launching a single Slice, you can view a persistent list of your
Slices.

Use the search bar to manually search for your Slices via URI (for example,
content://com.example.android.app/hello). Each time you search, the Slice is
added to the list.

Any time you launch the Slice Viewer tool with a Slice URI, the Slice is added
to the list.

You can swipe a Slice to remove it from the list.

Tap the URI of the Slice to see a page containing only that Slice. This has
the same effect as launching Slice Viewer with a Slice URI.

Note: Slice scrolling is disabled while displayed in the list. Launch your Slice
into the single Slice Viewer to test your scrollability.

Slice Viewer showing a list of Slices

View the Slice in different modes

An app that presents a Slice can modify the
SliceView#mode
at runtime, so you should make sure your Slice looks as expected in each mode.
Select the menu icon in the top-right area of the page to change the mode.

Kotlin

Java

Note: The SliceProvider template points to the AndroidX libraries by default.
If your project uses the legacy support libraries, make sure you modify the
build.gradle file to point to
com.android.support:slices-builders:(latest version) instead of the AndroidX
equivalent.Note: If you're using Kotlin, note that slice-builders-ktx is available only
in AndroidX. If you are using the legacy support library, use the standard
com.android.support:slices-builders:(latest version) library instead.

Each Slice has an associated URI. When a surface wants to display a Slice, it
sends a binding request to your app with this URI. Your app then handles this
request and dynamically builds the Slice via the
onBindSlice
method. The surface can then display the Slice when appropriate.

Below is an example of an onBindSlice method that checks for the /hello URI
path and returns a Hello World Slice:

Use the slice run configuration that you created in the Slice Viewer section
above, passing in your Slice URI (for example,
slice-content://com.android.example.slicesample/hello) of the Hello World
Slice to view it in the Slice Viewer.

Interactive Slices

Similar to notifications, you can handle clicks within your Slice by attaching
PendingIntent objects that are
triggered on user interaction. The example below starts an
Activity that can receive and handle those
intents: