views:

18

answers:

1

Hi, I am in one activity say Activity A. I am calling another activity B. In activity A I write the following Statement: startActivity(new Intent(this,ActivityB.class));

Now, I want to log a debug message only when Activity A is able to successfully launch ActivityB. How can I achieve this feature in Android. Any kind of Help is appreciated Thanks,

A: 

You can use the startActivityForResult method to achieve this. Use this in your Activity "A"

Or else if thats not what you are looking for, I am guessing you want to log when activity B starts and stos. Activity class provides lifecycle methods for start, stop, pause resume, etc. Override them and put your logging code in there:

  public class B extends Activity {

      private static final String TAG = "B-Activity";

      @Override
      public void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "Activity created"); // or Log.d for debug
      }

      @Override
      public void onStart() {
        Log.i(TAG, "Activity started"); // or Log.d for debug
      }

  }
naikus