free web tracker
Course Content
Java Programming Basics for Android
Learn the basics of Java programming for Android app development using Android Studio. This guide covers key concepts like variables, loops, and classes to help you start building your first Android apps with confidence. Perfect for beginners!
0/10
User Interaction and App Logic
Learn how to make your app respond to users! This section covers handling clicks, getting input, showing messages, switching screens, and saving simple data. A perfect start to build interactive Android apps with real logic.
0/10
Advanced Layouts and Components
Learn to build modern Android UIs using advanced layouts like RecyclerView, CardView, TabLayout, and more. This section helps beginners create beautiful, interactive, and user-friendly app interfaces step by step.
0/10
Media and Resources
Learn how to manage media and resources in Android Studio. This section covers adding audio, images, video, using drawables, custom fonts, and handling runtime permissions—essential for building rich, engaging Android applications.
0/4
Mastering Java Android Development – Beginner

In Android development, Toast messages are short popup notifications used to display feedback to users. Meanwhile, Logs are essential for debugging and tracking the app’s behavior during development. This guide will teach you how to use both in Java using Android Studio.

1. Showing Toast Messages in Java

Syntax

Toast.makeText(Context context, CharSequence text, int duration).show();

Example

Toast.makeText(MainActivity.this, "This is a Toast message", Toast.LENGTH_SHORT).show();

    • MainActivity.this refers to the current context.
    • "This is a Toast message" is the message to be displayed.
    • Toast.LENGTH_SHORT or Toast.LENGTH_LONG sets the duration.

Common Use

You can use Toast messages for:

    • Form validation feedback
    • Network status messages
    • Quick notifications without interrupting the UI

2. Writing Logs for Debugging

📌 Syntax

Log.d(String tag, String message);
Log.e(String tag, String message);
Log.i(String tag, String message);
Log.v(String tag, String message);
Log.w(String tag, String message);

Example

Log.d("MainActivity", "This is a debug log");

Log Types

    • Log.d – Debug
    • Log.i – Info
    • Log.e – Error
    • Log.v – Verbose
    • Log.w – Warning

Pro Tip

Always use a consistent tag name (like your activity name) to filter logs easily in Logcat.

How to View Logs in Logcat

    1. Open Android Studio.
    2. Click on Logcat at the bottom.
    3. Select your device and app process.
    4. Filter by tag or log level (Debug, Info, etc.).

Example in a Button Click

Button btn = findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Toast.makeText(MainActivity.this, "Button clicked!", Toast.LENGTH_SHORT).show();
        Log.d("MainActivity", "Button was clicked");
    }
});

Conclusion

Toast and Logcat are powerful tools in Android development:

    • Toast improves user interaction with visual feedback.
    • Logcat helps developers debug and trace issues efficiently.