I am creating a Splash
screen(Activity
) in my Android app. I have an inner class which extends AsyncTask
. The constructor for this inner class accepts a Context
object, which is being sent inside the Splash
activity's onCreate
method. There is also reference to a constant String
field.
public class Splash extends Activity {
private static final String TAG = "Splash";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new SplashAsyncTask(this).execute(new Void[] {});
}
private class SplashAsyncTask extends AsyncTask<Void, Void, Void> {
private Context context;
public SplashAsyncTask(Context context) {
this.context = context;
}
@Override
protected Void doInBackground(Void... params) {
try {
Thread.sleep(1500);
}
catch(InterruptedException e) {
if(Constants.LOGGING)
Log.e(TAG, e.toString());
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
}
}
what scope should i be using for the private static final String TAG = "Splash";
variable? all scopes seem to work fine, but what is proper/more efficient? I notice that eclipse automatically creates the variable with the public
scope declaration
Also, Do i really need to send the Context
object to the SplashAsyncTask
constructor? or can i/should i just use Splash.this
in all cases where i need a Context
reference?