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
orToast.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
– DebugLog.i
– InfoLog.e
– ErrorLog.v
– VerboseLog.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
- Open Android Studio.
- Click on Logcat at the bottom.
- Select your device and app process.
- 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.