Note that there are some explanatory texts on larger screens.

plurals
  1. POvariable scope with inner classes
    text
    copied!<p>I am creating a <code>Splash</code> screen(<code>Activity</code>) in my Android app. I have an inner class which extends <code>AsyncTask</code>. The constructor for this inner class accepts a <code>Context</code> object, which is being sent inside the <code>Splash</code> activity's <code>onCreate</code> method. There is also reference to a constant <code>String</code> field. </p> <pre><code>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&lt;Void, Void, Void&gt; { 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); } } } </code></pre> <p>what scope should i be using for the <code>private static final String TAG = "Splash";</code> variable? all scopes seem to work fine, but what is proper/more efficient? I notice that eclipse automatically creates the variable with the <code>public</code> scope declaration</p> <p>Also, Do i really need to send the <code>Context</code> object to the <code>SplashAsyncTask</code> constructor? or can i/should i just use <code>Splash.this</code> in all cases where i need a <code>Context</code> reference?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload