How to build an Android Recycle Bin App - Hive Programmers

avatar
(Edited)

Greetings to my favorite science community online, StemSocial.

It's @skyehi and I'm super excited to be back in this community to continue my epic series on Android App development tutorials for beginners.

In yesterday's tutorial, we were able to successfully build an AI Android App powered by a pre-trained AI model library. It got good feedback and I'm very grateful.

One software that has been on computers for as long as I could remember is the Recycle Bin App. This is an App designed to hold a compressed version of any data or item you delete from your computer.

Recycle Bins are very important for when you want to delete apps, images, videos, audio or any piece of information and are not sure if you would need it again.

Recycle bins are true live savers when it comes to recovering your deleted file.

In today's blog, I'm going to take you through a simple tutorial of how to build a recycle bin App for Android.

Polish_20231212_150224266.jpgOriginal Image Source by Pixabay from Pexels

YpihifdXP4WNbGMdjw7e3DuhJWBvCw4SfuLZsrnJYHEpsqZFkiGGNCQTayu6EytKdg7zA3LL2PbZxrJGpWk6ZoZvBcJrADNFmaFEHagho8WsASbAA8jrpnELSvRtvjVuMiU1C5ADFX1vJgcpDvNtue9Pq83tjBKX62dqT5UoxtDk.png

Our Recycle Bin App will have two screens, one for displaying images and another for viewing deleted images inside the recycle bin.

Since this is a beginner's guide, we'll only build the App to hold deleted Images for now. In more advanced tutorials, we'll work on a full Recycle Bin App to hold every single deleted file in your phone.

Hope you're excited about this tutorial guys, let's get started shall we

Prerequisites

This step is for the benefit of newcomers to my series since if you've been following the series till date, you should already have the required tools to go through with this tutorial.

You would need to download two main softwares, Android Studio IDE and the Java Development Kit, JDK.
Android studio is the platform we'll be building our Apps on and JDK is needed for your computer to be able to execute Java code.

If you're having troubles installing any of these
softwares, please let me know in the comments guys

2dk2RRM2dZ8gKjXsrozapsD83FxL3Xbyyi5LFttAhrXxr16mCe4arfLHNDdHCBmaJroMz2VbLrf6Rxy9uPQm7Ts7EnXL4nPiXSE5vJWSfR53VcqDUrQD87CZSpt2RKZcmrYrze8KanjkfyS8XmMCcz4p33NZmfHE4S9oRo3wU2.png

Creating a new Android Studio Project.

As we usually do in the series, we'll start by creating a new Android studio Project. Go ahead and open Android Android and click on "Create a new Android Project"

You can choose the App name and package name of your App. Also ensure that Java is the selected programming language and not Kotlin. Finally, choose Empty Activity as the template of our App Project.

When you're through with these steps, click finish and Android Studio will create a whole new Android Project for you.

Now guys, this project will be divided into 4 main project screens. We'll build the frontend and backend of a screen to display images and we'll build the frontend and backend of another screen to view the deleted screens.

This means we'll have two XML files and Two main Java files.

XML Layout for the Main Screen (Displaying Images)

Alright guys, we're going to start with the XML layout screens. This screen will be designed to display Images from your phone. If there's no image on your device, a text with the inscription "Recycle bin is empty" will be displayed.

So we'll build two elements, a RecyclerView to hold the images and a TextView to display the message when screen is empty. Pretty easy right guys?

Here's how your code should look like

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/emptyStateTextView"
        android:clipToPadding="false"
        android:paddingBottom="16dp"/>

    <TextView
        android:id="@+id/emptyStateTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Recycle bin is empty"
        android:visibility="gone"/>
</RelativeLayout>

YpihifdXP4WNbGMdjw7e3DuhJWBvCw4SfuLZsrnJYHEpsqZFkiGGNCQTayu6EytKdg7zA3LL2PbZxrJGpWk6ZoZvBcJrADNFmaFEHagho8WsASbAA8jrpnELSvRtvjVuMiU1C5ADFX1vJgcpDvNtue9Pq83tjBKX62dqT5UoxtDk.png

XML Layout for the Recycle Bin Screen (Viewing Deleted Images)

Let's now work on the second XML layout screen which will be used to view the deleted images. This will look like the first layout. We'll have two elements too, a RecyclerView and a TextView.

If there's no deleted image, a text with the inscription "Recycle bin is empty" will be displayed. When an image is deleted, the text will be replaced with the Recycleview showing all the deleted images.

Here's how your code should look like guys

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context=".RecycleBinActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycleBinRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/emptyStateTextView"
        android:clipToPadding="false"
        android:paddingBottom="16dp"/>

    <TextView
        android:id="@+id/emptyStateTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Recycle bin is empty"
        android:visibility="gone"/>
</RelativeLayout>

YpihifdXP4WNbGMdjw7e3DuhJWBvCw4SfuLZsrnJYHEpsqZFkiGGNCQTayu6EytKdg7zA3LL2PbZxrJGpWk6ZoZvBcJrADNFmaFEHagho8WsASbAA8jrpnELSvRtvjVuMiU1C5ADFX1vJgcpDvNtue9Pq83tjBKX62dqT5UoxtDk.png

Backend Code for MainActivity (Displaying Images)

Alright guys, let's start working on our backend code for displaying images. This is a model of the code and I'm only assuming that you have a list of image files (imageList and deletedImagesList) and also RecyclerView adapters set up for both screens

Remember that you would need to create adapters that represent each image thumbnail and image Title. I would leave further customization in your hands guys.

If you're having troubles creating the adapter or include your image lists, let me know in the comments and I'll send the other codes.

We are only working on a basic apps for beginners, as things get more advanced, more details will be included guys.

Here's how a model of your backend code should look like

// MainActivity.java
public class MainActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private List<File> imageList; // Assume you have a list of image files

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        recyclerView = findViewById(R.id.recyclerView);
        // Initialize imageList and set up the RecyclerView adapter
        // ...

        // Check for empty state
        if (imageList.isEmpty()) {
            findViewById(R.id.emptyStateTextView).setVisibility(View.VISIBLE);
        }
    }
}

YpihifdXP4WNbGMdjw7e3DuhJWBvCw4SfuLZsrnJYHEpsqZFkiGGNCQTayu6EytKdg7zA3LL2PbZxrJGpWk6ZoZvBcJrADNFmaFEHagho8WsASbAA8jrpnELSvRtvjVuMiU1C5ADFX1vJgcpDvNtue9Pq83tjBKX62dqT5UoxtDk.png

Backend Code for RecycleBinActivity (Viewing Deleted Images)

It's time to write the backend code for the recycle bin screen. Like I said earlier, I'll assume you have a list of deleted image files. I may not be able to delete a file on your behalf otherwise I would have 😂.

In this backend code, what you need to do is to initialize the deletedImagesList and also do not forget to setup the Adapter of the Recycleview of your Recycle Bin Screen.

It's not complicated at all guys. With how far we have come on this series, I'm hoping you can go through this step yourself. However, if you're having troubles doing that, don't worry guys, the future projects will include details of every single code needed.

Putting all the necessary codes together in a beginner's guide may seem a bit too much and I don't intend to overwhelm my readers.

Here's how a model of the backend code should look like guys

// RecycleBinActivity.java
public class RecycleBinActivity extends AppCompatActivity {

    private RecyclerView recycleBinRecyclerView;
    private List<File> deletedImagesList; // Assume you have a list of deleted image files

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycle_bin);

        recycleBinRecyclerView = findViewById(R.id.recycleBinRecyclerView);
        // Initialize deletedImagesList and set up the RecyclerView adapter
        // ...

        // Check for empty state
        if (deletedImagesList.isEmpty()) {
            findViewById(R.id.emptyStateTextView).setVisibility(View.VISIBLE);
        }
    }
}

Now guys since our Recycle Bin app will involve accessing files, we'll definitely need to request the appropriate permissions in the AndroidManifest.xml file.

We'll need to request the READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions.

Here's how the code should look like

<manifest xmlns:android="https://schemas.android.com/apk/res/android"
    package="your.package.name">

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

</manifest>

2dk2RRM2dZ8gKjXsrozapsD83FxL3Xbyyi5LFttAhrXxr16mCe4arfLHNDdHCBmaJroMz2VbLrf6Rxy9uPQm7Ts7EnXL4nPiXSE5vJWSfR53VcqDUrQD87CZSpt2RKZcmrYrze8KanjkfyS8XmMCcz4p33NZmfHE4S9oRo3wU2.png

Finishing Touches

Like I said earlier on guys, this is merely a model of a full Recycle Bin App. You'll actually need to replace the placeholder comments with your code logic. You're totally free to customize the code according to your app's requirements.

Thanks so much for taking the time to read today's blog. I hope you enjoyed this tutorial. We are gradually getting closer and closer to the Intermediary level of our tutorials. We'll switch the language to Kotlin and build very advanced and complex Apps.

Trust me guys, you'll be professional Android App developers in no time. Have fun coding guys.

Have a lovely day and catch you next time in StemSocial. Goodbye 👨‍💻


You Can Follow Me @skyehi For More Like This And Others



0
0
0.000
3 comments
avatar
(Edited)

redacted

avatar

Sorry about that😁 it was a typo error, I'v edited it now. Everything should be just fine and it was even an example link.

I hope you enjoy the Tutorials. Stay tuned for me friend🥰

0
0
0.000
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

Thanks for including @stemsocial as a beneficiary, which gives you stronger support. 
 

0
0
0.000