How to Create Static Shortcuts in Android App?
Last Updated :
16 Jul, 2024
An application might contain several services for the user and to facilitate a user quickly to those services, shortcuts are used. Shortcuts for an application are a list of features (quick services) that helps the users to easily and quickly jump to particular features or activities within the application. Shortcuts are listed and constructed depending on the services that it provides. Shortcuts of an application (if they are built explicitly) could be seen as a list of items when long-pressed on the application icon as below.
In this article, let's demonstrate the implementation of fixed (static) shortcuts for various activities in the application. But first, we need to know what Static here means. Static Shortcuts are a set of pre-defined shortcuts those hard-coded inside the application program. They do not change with time or user actions. They are fixed and can be accessed anytime, even if the application is not running in the background. Regarding the Shortcuts, at maximum, an application can have only 4 shortcuts. If multiple shortcuts are declared inside the program, then only the first four shortcuts are available inside the list. This is to improve the Shortcut's visual appearance.
Approach
Step 1: Create a new project
Please refer to How to Create/Start a New Project in Android Studio for creating an Empty Activity. Note that use Kotlin as the primary language for this project.
Step 2: Create an Android Resource File (xml) in res/xml folder
Go to res -> Android Resource file and create an android resource file as shown below.

Create a file where we could store all the shortcuts. An Android Resource File which has an XML format is created where we program all the Shortcuts. The file path to save this file is res/xml/shortcuts.xml. There no need to alter any other parameter and click OK.

Once the file is generated, Shortcuts can be declared, but before, declare meta-data in the Android Manifest to link shortcuts.xml file as a resource for the application.
Step 3: Declaring shortcuts.xml file as a resource for Application Shortcuts
In the AndroidManifest.xml file, meta-data is to be declared inside the activity as shown in the following code.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.geeksforgeeks.static_shortcuts">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Activity3"></activity>
<activity android:name=".Activity2" />
<activity android:name=".Activity1" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Meta Data for linking the shortcuts.xml file to the Application Shortcuts -->
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
</application>
</manifest>
 Step 4: Set the Target SDK Version inside the App Gradle to 26
Shortcuts are only supported by Android Devices with API level 25 and above. For self-assurance, set the targetSDKVersion to 26.Â

Step 5: Configuring the shortcuts.xml file for generating different Shortcuts
Since this is an XML file, the structure of this file would be in the form of hierarchical elements. <shortcuts> is the root element and <shortcut> elements define the context of the shortcut. A shortcut mainly comprises of 6 parameters and 1 intent with 3 parameters. We now define each one of them briefly.
Parameters of a shortcut element:Â
Elements | Description |
---|
android:shortcutID | A string literal, which represents the shortcut when a ShortcutManager object performs operations on it. |
android:enabled | Determines whether the user can interact with the shortcut from a supported launcher, either true or false. |
android:shortcutShortLabel |  A concise phrase that describes the shortcut's  purpose up to 10 characters. |
android:shortcutLongLabel | An extended-phrase that describes the shortcut's  purpose up to 25 characters. |
android:shortcutDisabledMessage | The message that appears in a supported launcher when the user attempts to launch a disabled shortcut. |
android:icon | Displaying icon against the shortcut. |
An icon is to be created in the res/drawable folder by right-clicking it and clicking the image/vector asset. Refer to the below image.

Select vector asset and choose clipart, gave it a name icon.xml as shown below.Â

Intent Parameters:
Parameters | Description |
---|
android:action | The action that the system launches when the user selects the shortcut. |
android:targetPackage | Package of the application. |
android:targetClass | Class of the application where the shortcut wants users to redirect. |
Code for shortcuts.xml file:
Just to visualize the shortcut, parameters shortcutID, enabled, icon, shortcutShortLabel are needed and rest can be ignored. These values are random and defined them in res/values/strings.xml file which is available in the later sections of this article. Here Intents acts the same way as they do while sending the user from one activity to another. When the user holds the application icon for 2 seconds, 4 shortcuts appear, clicking on which different activities of the application are opened. Refer to the comments in the below program.Â
Note:Â
android:targetClass="org.geeksforgeeks.static_shortcuts.MainActivity"
android:targetPackage="org.geeksforgeeks.static_shortcuts"Â
Remember that input your project package name here.
shortcuts.xml
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Shortcut 1:
Navigates the user to MainActivity through the intent -->
<shortcut
android:enabled="true"
android:icon="@drawable/icon"
android:shortcutId="compose0"
android:shortcutShortLabel="@string/compose_shortcut_short_label0">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="org.geeksforgeeks.static_shortcuts.MainActivity"
android:targetPackage="org.geeksforgeeks.static_shortcuts" />
</shortcut>
<!-- Shortcut 2:
Navigates the user to Activity1 through the intent -->
<shortcut
android:enabled="true"
android:icon="@drawable/icon"
android:shortcutId="compose1"
android:shortcutShortLabel="@string/compose_shortcut_short_label1">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="org.geeksforgeeks.static_shortcuts.Activity1"
android:targetPackage="org.geeksforgeeks.static_shortcuts" />
</shortcut>
<!-- Shortcut 3:
Navigates the user to Activity2 through the intent -->
<shortcut
android:enabled="true"
android:icon="@drawable/icon"
android:shortcutId="compose2"
android:shortcutShortLabel="@string/compose_shortcut_short_label2">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="org.geeksforgeeks.static_shortcuts.Activity2"
android:targetPackage="org.geeksforgeeks.static_shortcuts" />
</shortcut>
<!-- Shortcut 4:
Navigates the user to Activity3 through the intent -->
<shortcut
android:enabled="true"
android:icon="@drawable/icon"
android:shortcutId="compose3"
android:shortcutShortLabel="@string/compose_shortcut_short_label3">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="org.geeksforgeeks.static_shortcuts.Activity3"
android:targetPackage="org.geeksforgeeks.static_shortcuts" />
</shortcut>
</shortcuts>
Step 6: Creating Different Activities for Shortcuts
To check if the shortcuts are throwing the user to different activities, add 3 more Activities to the project: Activity1, Activity2, and Activity3. These activities are implemented in the above code as well. Below are the frontend codes for these activities. Activity1.kt, Activity2.kt, Activity3.kt have the same codes.
Activity1.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity1">
<!-- Activity 1-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Activity 1"
android:textSize="40sp"
/>
</RelativeLayout>
Activity1.kt
package org.geeksforgeeks.static_shortcuts
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class Activity1 : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_1)
}
}
Activity2.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity2">
<!-- Activity 2-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Activity 2"
android:textSize="40sp"
/>
</RelativeLayout>
Activity2.kt
package org.geeksforgeeks.static_shortcuts
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class Activity2 : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_2)
}
}
Activity3.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity3">
<!-- Activity 3-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Activity 3"
android:textSize="40sp"
/>
</RelativeLayout>
Activity3.kt
package org.geeksforgeeks.static_shortcuts
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class Activity3 : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_3)
}
}
 Step 7: Configuring MainActivity.kt and activity_main.xml
The MainActivity.kt is the main and the first activity of the application. Buttons are added to navigate to other activities. Refer to the comments inside the code.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Main Activity"
android:textSize="40sp"
android:layout_centerHorizontal="true"
android:layout_above="@id/btn2"/>
<!-- Button for navigating to Activity 1 -->
<Button
android:id="@+id/btn1"
android:text="Activity1"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<!-- Button for navigating to Activity 2 -->
<Button
android:id="@+id/btn2"
android:text="Activity2"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<!-- Button for navigating to Activity 3 -->
<Button
android:id="@+id/btn3"
android:text="Activity3"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
MainActivity.kt
package org.geeksforgeeks.static_shortcuts
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Just to check if these buttons starts other activities
// Declaring Buttons
val btn1 = findViewById<Button>(R.id.btn1)
val btn2 = findViewById<Button>(R.id.btn2)
val btn3 = findViewById<Button>(R.id.btn3)
// Intents when buttons are pressed
// Takes to Activity 1
btn1.setOnClickListener
{
startActivity(Intent(this, Activity1::class.java))
}
// Takes to Activity 2
btn2.setOnClickListener
{
startActivity(Intent(this, Activity2::class.java))
}
// Takes to Activity 3
btn3.setOnClickListener
{
startActivity(Intent(this, Activity3::class.java))
}
}
}
Step 8: Modify the Strings.xml file
These string values(compose....label1, label2, label3, label0) declared under res/values/strings.xml define the string that is to be shown as shortcut labels for the shortcuts when the shortcut list expands.
Strings.xml
<resources>
<string name="app_name">Static_Shortcuts</string>
<string name="compose_shortcut_short_label0">MainActivity</string>
<string name="compose_shortcut_short_label1">Activity 1</string>
<string name="compose_shortcut_short_label2">Activity 2</string>
<string name="compose_shortcut_short_label3">Activity 3</string>
</resources>
 Output: Run on Emulator
Similar Reads
How to Create Your Own Shortcut in Android Studio?
Android Studio is the official integrated development environment for Googleâs Android operating system, built on JetBrainsâ IntelliJ IDEA software and designed specifically for Android app development. Android Studio offers a lot of shortcuts to users. It also provides to configure Keymap and add y
2 min read
How to Add Capabilities to Shortcuts in Android 13?
Shortcuts have been an integral part of Android Apps, almost every app we use has shortcuts that facilitate main activity opening with various time-savers, which turn out to be great time savers. Over the years this experience has greatly improved, and now we can add even more capabilities to our ap
4 min read
How to Create a Wallpaper App in Android Studio?
Almost all Android devices are having a wallpaper set on their home screen. For setting this wallpaper to the screen many Android devices provides a Wallpaper Application where we can browse different types of wallpapers based on various categories. In this article we will look at, building a simila
15+ min read
How to Create/Start a New Project in Android Studio?
After successfully installing the Android Studio and opening it for the first time. We need to start with some new projects to start our journey in Android.In this article, we will learn about How to Create a New Project in Android Studio.Steps to Create/Start a New Android Project in Android Studio
2 min read
How to Create Dynamic Shortcuts of an Android Applications?
In Android Phones, when an Application is held for more than a second, certain app actions appear in a list. These app actions are nothing but shortcuts for performing and actions without opening the application. Shortcuts for an application are a list of features (quick services) that helps the use
5 min read
How to Use Static Method in Android?
Android is an open-source operating system, based on the Linux kernel and used in mobile devices like smartphones, tablets, etc. Further, it was developed for smartwatches and Android TV. In this article, we are going to see how we can implement static methods in Android. We will be creating static
5 min read
How to Create Balloon Toast Message in Android?
In this article, we are going to creating a balloon Toast. This Library is one of the popular features that is commonly used in most Android Apps. We can get to see this feature in most of the shopping and messaging apps. With the help of this feature, you can get a hint about what to do next in any
2 min read
How to Create Admin & Client App in One Project Using Android Studio?
You all must know about projects in which two applications are required one for the client and the other for the admin. Here we will see how we can implement both the applications under a single project in android studio. Let us see the step-by-step implementation of this procedure. Step by Step Imp
2 min read
How to Build a Simple Notes App in Android?
Notes app is used for making short text notes, updating when you need them, and trashing when you are done. It can be used for various functions as you can add your to-do list in this app, some important notes for future reference, etc. The app is very useful in some cases like when you want quick a
9 min read
How to Create an Onboarding Screen in Android?
Hello geeks, today we are going to learn that how we can add Onboarding Screen to our android application in the android studio so that we can provide a better user experience to the user of the application. What is Onboarding Screen? The onboarding screen can be understood as a virtual unboxing of
4 min read