Table of Contents
Shortcuts in Android App provides a list of features or contents to the users, which assist the users in speedy access of a particular features within the application. The Shortcut content delivery depends on whether the Shortcut context is user-driven/app-driven and also depends on the way of operation by the users. However the context of static shortcuts will not change, whereas the context of dynamic shortcuts will change constantly. The context of both static/dynamic are driven by your app. In case of pinned shortcut, the users can decide the way to deliver content to them. So the context is user defined.
Shortcuts in Android Apps are listed and put up depending on the service and operation they provide. Application shortcuts are entered as a list of units on the application icon when long-pressed. This article ‘How to Create Static Shortcuts In Android App?’ will provide information regarding the implementation of static shortcuts for performing various activities within the application. Read article ‘How to Create Static Shortcuts In Android App?’ for more details!
Static Shortcuts
Prior to all the actions, the users must know what actually ‘Static’ here means. A set of pre-built shortcuts that are internally hard-coded in an application program. These entered shortcuts will remain the same with time/users operations. Static shortcuts are fixed and that can be accessed at users convenience, even if the application is not working in the background. An application contains a maximum of four shortcuts. Only first four shortcuts are made available in the list, In order to upgrade the visual appearance of shortcuts.
Static Shortcuts are good for apps that link to content using a compatible firm throughout the lifespan of users inter-linkage with the app.
Create Static Shortcuts
1: Which of the following data structures allows elements to be added and removed in a Last-In, First-Out (LIFO) order?
Static Shortcuts gives links to collective activities within your application. These activities and features in your app should be consistent throughout the lifetime of your app. Follow the given steps to create Static Shortcuts in your Android App;
-
Start a new project
Start by adding the meta-data to the operation with reference to an XML resource file. below discussed steps will explain the file in detail;
-
Create an Android Resource File in res/ xml folder
For creating an android resource file, Go to- Android Resource File (res). A new file is created to reserve all the shortcuts. For programming the shortcuts, an android resource file with xml format is constructed. Save file-res/xml/shortcuts.xml and click OK. After generating the file, the shortcuts can be declared.
-
Declaration of shortcuts.xml file for App Shortcuts
In the resource file, we can define one or more shortcuts. But always the file should begin with a shortcut tag, and in that we can attach multiple shortcuts.
<?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> |
-
Design the shortcuts.xml file for creating different Shortcuts
A shortcut contains six parameters,1 intent with three parameters.
Specifications of a shortcut element;
Tabulated below are the parameters of shortcut elements
Elements |
Specifications |
android:shortcutID |
When shortcut manager object performs action on it, then a string will represent the shortcut |
android:enabled |
Decides whether the users can interrelate with shortcut from a supported launcher(true/false) |
android:shortcutLongLabel |
Its an extended expressions that defines the shortcuts use up to 25 features |
android:shortcutShortLabel |
A short phrase that defines the shortcuts use up to 10 features |
android:icon |
It displays icon against the shortcuts |
android:shortcutDisabledMessage |
When a user try to launch a disabled shortcut, then a message will appear on the supported launcher |
Get the latest Coding notes for free
-
Generating different activities for Shortcuts
Reorienting Strings.xml file
<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> |
The shortcut labels are defined in res/values/strings.xml.
Shortcuts.xml file Code
- ShortcutID, parameters, shortcutShortLabel, enabled, icon are required to contemplate the shortcut.
- The values are defined systematically in the res/values/strings.xml file.
- When a user operates an application icon for 2-3 seconds, four shortcuts are displayed. Where users can click and access the activities of the application.
Download the Entri App now! for the latest updates in Android App
Static shortcuts provide a loop to collective actions or activities within your app. To create one a user must know the steps involved. Hope this article ‘How to Create Static Shortcuts in Android App?’ will benefit the android app users.