Thursday, November 21, 2013

[Android] Example showing how to print log in log cat

This is a simple example to show how to use the log i android project development.
you can open a project named "http_test" ,
Activity Name named "MainActivity",
and copy the code to MainActivity.java to try:
package com.example.http_test;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
private static final String ACTIVITY_TAG="Xenia";
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     
        Log.v(MainActivity.ACTIVITY_TAG, "This is Verbose.");
        Log.d(MainActivity.ACTIVITY_TAG, "This is Debug.");
        Log.i(MainActivity.ACTIVITY_TAG, "This is Information");
        Log.w(MainActivity.ACTIVITY_TAG, "This is Warnning.");
        Log.e(MainActivity.ACTIVITY_TAG, "This is Error.");
        setContentView(R.layout.activity_main);                
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}  
Result:

Offiical reference.
http://developer.android.com/reference/android/util/Log.html

No comments :

Post a Comment