Я разрабатываю приложение, используя API Youtube. Я не знаю, какой контекст должен пройти в Intent.I пробовал this
, getApplicationContext()
, VideoActivity.this
и тот, который использовался ниже. Я уже упоминал некоторые подобные вопросы, но они мне не помогают. Итак, пожалуйста, кто-нибудь скажет мне, что такое различия между этими контекстами.Какой контекст я должен использовать здесь?
public class VideoActivity extends Activity {
private static final String TAG = "FeedListActivity";
private static final int REQ_START_STANDALONE_PLAYER = 1;
private static final int REQ_RESOLVE_SERVICE_MISSING = 2;
private static final String PLAYLIST_ID = "*******";
public static final String DEVELOPER_KEY = "*******";
public ListView listView;
private FeedListAdapter listAdapter;
private List<FeedItem> feedItems;
public String mvideoid;
private String URL_FEED = "http://www.amsoin.net/ins/nes.json";
Context mContext;
public VideoActivity (Context context){
mContext = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feed_list);
listView = (ListView) findViewById(R.id.feed_list);
feedItems = new ArrayList<FeedItem>();
listAdapter = new FeedListAdapter(this, feedItems);
listView.setAdapter(listAdapter);
// making fresh volley request and getting json
GsonRequest<FeedResult> gsonRequest = new GsonRequest<FeedResult>(URL_FEED, FeedResult.class,
new Response.Listener<FeedResult>() {
@Override
public void onResponse(FeedResult response) {
feedItems = response.getFeedItems();
listAdapter.setData(feedItems);
listAdapter.notifyDataSetChanged();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Error: " + error.getMessage());
}
});
// Adding request to volley request queue
AppController.getInstance().addRequest(gsonRequest, TAG);
}
public void Play(View v) {
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.d(TAG,mvideoid);
int startIndex = 0;
int startTimeMillis = 0;
boolean autoplay = true;
boolean lightboxMode = false;
Intent intent = null;
**intent = YouTubeStandalonePlayer.createPlaylistIntent(mContext, DEVELOPER_KEY,
PLAYLIST_ID, startIndex, startTimeMillis, autoplay, lightboxMode);**
startActivity(intent);
if (intent != null) {
if (canResolveIntent(intent)) {
startActivityForResult(intent, REQ_START_STANDALONE_PLAYER);
} else {
// Could not resolve the intent - must need to install or update the YouTube API service.
YouTubeInitializationResult.SERVICE_MISSING
.getErrorDialog(mContext, REQ_RESOLVE_SERVICE_MISSING).show();
}
}
}
});
}
* VideoActivity.this * – Blackbelt
'v.getContext()' – codeMagic