通过BaseActivity知晓当前是哪一个Activity

package com.itheima74.baseactivity;

import android.support.v7.app.AppCompatActivity;
import android.util.Log;

/**
 * BaseActivity是父类,复写了onResume()方法,
 * 每次Activity获取焦点时执行该方法,
 * MainActivity,SecondActivity,ThirdActivity是子类,
 * 他们继承了父类的属性和方法.
 * Created by My on 2017/2/28.
 */

public class BaseActivity extends AppCompatActivity {

    private static final String TAG = "BaseActivity";

    @Override
    protected void onResume() {
        super.onResume();
        Log.i(TAG, getClass().getSimpleName());
    }
}
package com.itheima74.baseactivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    // 点击按钮,启动SecondActivity
    public void click(View view){
        startActivity(new Intent(this,SecondActivity.class));
    }
}
package com.itheima74.baseactivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class SecondActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
    }

    // 点击按钮,启动ThirdActivity
    public void click(View view) {
        startActivity(new Intent(this, ThirdActivity.class));
    }
}
package com.itheima74.baseactivity;

import android.os.Bundle;

public class ThirdActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_third);
    }
}

通过BaseActivity知晓当前是哪一个Activity_第1张图片

你可能感兴趣的:(Android)