Android's Clipboard facilitates copying and pasting across various data types, including text strings, images, binary stream data, and other complex data formats. The Clipboard functionality enables these operations within the same application as well as between multiple applications that have integrated the clipboard framework. It's important to note that the clipboard has a restriction on the number of objects it can store simultaneously, allowing only one object at a time. When a new object is placed on the clipboard, the previously stored object is replaced. The clip object within the clipboard can accommodate three primary data types:
Text:To build an application on Android that saves and retrieves data from the clipboard, the following steps are followed:
Let's first understand the process with the help of a GIF. This project will be implemented using the Kotlin language.
<?xml version="1.0" encoding="utf-8"?> |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> |
<EditText android:id="@id/txtCopy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/btnCopy" android:layout_centerHorizontal="true" android:hint="Type something..." /> |
<Button android:id="@id/btnCopy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Copy to Clipboard" /> |
</RelativeLayout> |
A sample GIF is given below to get an idea about what we are going to do in this section.
Below is the code for the activity_main.xml file.
Go to the MainActivity.kt file, and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.
00:25 |
Ready to embark on an exciting journey into the world of Android Development with Kotlin? It's time to make a change and dive into a fantastic learning experience with our Mastering Android Development with Kotlin From Beginner to Pro - Self Paced!