Elenasys Elenasys - 4 months ago 45
Android Question

AndroidRuntimeException "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag"

I create multiple layouts inside a listview, but when i click i get a AndroidRuntimeException "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?"

Im adding


Intent.FLAG_ACTIVITY_NEW_TASK


to my intent but i get the same message! =(

@Override
public View getView(int position, View convertView, ViewGroup parent) {

retval=LayoutInflater.from(getApplicationContext()).inflate(R.layout.layout_anuncio, null);
ImageView image=(ImageView) retval.findViewById(R.id.imageAD);
LoadAds loadAds= new CargaAnuncios();
clickUrl = LoadAds.cargaImagenAnuncio(image, mContext, GlobalInfo.ANUNCIO_CARRIL_PORTADA);
image.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View view) {
Bundle bundle=new Bundle();
bundle.putString("url", clickUrl);
Intent intent =new Intent(mContext,CustomWebView.class);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}

});
return retval;
}

Answer

I have added:

parent.getApplicationContext()

Instead of just:

getApplicationContext()

Whole line is:

retval=LayoutInflater.from(parent.getApplicationContext()).inflate(R.layout.layout_anuncio, null);