কম্পিউটার টিউটোরিয়াল

Android-এ বাটন দিয়ে হোম স্ক্রিনে যাওয়ার পদ্ধতি


ইন্টেন্ট ব্যবহার করে হোম স্ক্রিনে যাওয়ার উদাহরণ

এই উদাহরণটি দেখায় কিভাবে `Intent.ACTION_MAIN` এবং `Intent.CATEGORY_HOME` ব্যবহার করে বাটন ক্লিক করলে হোম স্ক্রিনে যাওয়া যায়।

ধাপ ১: নতুন প্রজেক্ট তৈরি করুন

Android Studio-তে File → New Project এ যান এবং প্রয়োজনীয় বিবরণ পূরণ করে একটি নতুন প্রজেক্ট তৈরি করুন।

ধাপ ২: লেআউট XML-এ বাটন যোগ করুন

res/layout/activity_main.xml ফাইলে নিচের কোডটি যোগ করুন:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:tools="https://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16sp"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="হোম স্ক্রিনে যান"/>

</RelativeLayout>

ধাপ ৩: MainActivity.java-এ ইন্টেন্ট লজিক লিখুন

src/MainActivity.java ফাইলে নিচের কোডটি যোগ করুন:

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

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

        Button button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent startMain = new Intent(Intent.ACTION_MAIN);
                startMain.addCategory(Intent.CATEGORY_HOME);
                startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(startMain);
            }
        });
    }
}

ধাপ ৪: AndroidManifest.xml কনফিগার করুন

androidManifest.xml ফাইলে নিচের কোডটি নিশ্চিত করুন:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
    package="app.com.sample">

    <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=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

অ্যাপ্লিকেশন চালানোর পদ্ধতি

আপনার Android ডিভাইস কম্পিউটারের সাথে সংযুক্ত করুন। Android Studio-তে প্রজেক্টের activity ফাইল খুলে টুলবারের Run আইকনে ক্লিক করুন। আপনার মোবাইল ডিভাইস সিলেক্ট করুন এবং বাটনে ক্লিক করলে হোম স্ক্রিনে যাবে।

Android-এ বাটন দিয়ে হোম স্ক্রিনে যাওয়ার পদ্ধতি

Android-এ বাটন দিয়ে হোম স্ক্রিনে যাওয়ার পদ্ধতি

  1. Android-এ Home Button ওভাররাইড/হ্যান্ডল করার পদ্ধতি

  2. ক্রোমবুক হোম স্ক্রিনে উইজেট যোগ করার উপায়

  3. Android-এ হোম স্ক্রিন অ্যাসাইন করার পদ্ধতি

  4. অ্যান্ড্রয়েডে হোম বাটন দিয়ে ক্যামেরা লঞ্চ করার পদ্ধতি