loading

This app only shows the known "hello world" message, what we are trying to do here is to understand how the activity behaves in order for this simple app to show up.

Step 1: Import Lag Class

We are going to import the class Lag into our code, this class is responsible for showing logging messages in our console, these messages will help you keep on track with the method running at the moment, and thus understand the cycle of the activity.

Make sure you type Log with capital "L".

Step 2: Name Your Tag

Now we name our tag with the string "the messages!", of course you can name it whatever you want.

This is done by creating a string variable MY_TAG that shows the string "the messages!".

Step 3: Write the Message You Want to Show on Logcat

To log this, we're going inside onCreate method and write:

Log.i(MY_TAG,"onCreate now");

where Log.i() is a function that takes two strings, one of them is the tag and the other will be the message we want to show on logcat once the method onCreate() starts running.

Step 4: Create OnStart Method

Now we create onStart() method. All we need here is to test Log.i() method so not much will be written inside onStart method, only the following:

@Override

protected void onStart(){

super.onStart();

Log.i(MY_TAG, "onStart now");

}

Step 5: Create All Other Methods

Copy what you wrote for onStart() and paste it for on Restart(), onResume(), and onStop() methods, with changing necessary lines, as shown in the picture.

Step 6: Edit Logcat Configurations

Now go to Activity_Main.xml, and choose Android monitor>> logcat, go to the drop menu to the right and choose "Edit filter configurations", this option will filter all messages so you can only get these we made.

In the box that shows up you will have the following options:

Name: choose any name you like, I named mine "TryMessages"

Log tag: write in the tag name, in our case it's "the messages!"

Step 7: Finally!

After the tag is created, make sure you choose this tag not any other option.

Now run the app on your emulator, you will be able to see the different messages when you open, resume , or close and restart your application.

In case log messages don't show up, it means that the debugging option is off, click(shift+f9), then ok. This will enable adb server and thus the debugging mode.

To make this instructable I used some help from this video :

and some problem solving comments from stackoverflaw

<p>Thanks for sharing :)</p>

About This Instructable

162views

2favorites

License:

More by hadear Abul-hagag:Apple Packaging System Simulation Using PIC Activity Cycle Android App 
Add instructable to: