2012-10-11 10 views
5

doInBackground के अंदर मुझे एप्लिकेशन संदर्भ या गतिविधि का संदर्भ देना होगा।AsyncTask doInBackground पैरामीटर बनाम कन्स्ट्रक्टर पैरामीटर

क्या थ्रेड सुरक्षा और अन्य संभावित बहु-थ्रेड अवधारणाओं, प्रतिबंधों के संदर्भ में new MyAsyncTask(getApplicationContext()) और doInBackground(Context... params) के बीच कोई अंतर है?

धन्यवाद।

private class MyAsyncTask extends AsyncTask<Context, Integer, Long> { 
    private Context _context = null; 

    MyAsyncTask(Context context) { 
    _context = context; 
    } 

    protected Long doInBackground(Context... context) { 
    // if _context and context are the same, it doesn't matter 
    // which you use. 
    return 0; 
    } 

    protected void onProgressUpdate(Integer... progress) { 
    // update progress 
    } 

    protected void onPostExecute(Long result) { 
    // publish result 
    } 
} 

तो फिर वहाँ कोई अंतर्निहित संदर्भ में ही बहु सूत्रण wrt के बारे में मुद्दे हैं:

+0

देखें @ राहुल http://developer.android.com/reference/android/os/AsyncTask.html –

+0

, अंतर बताने – midnight

उत्तर

1

नहीं। आप यह मानते हुए की तरह कुछ है।

Context useMe = getApplicationContext(); 
MyAsyncTask task = new MyAsyncTask(useMe); 
task.execute(useMe); // should use this if provided, otherwise, what was in constructor 
संबंधित मुद्दे