androidandroid-intentcustom-adaptergetview

java.lang.reflect.InvocationTargetException appears while starting Activity


This is a block of code inside my ListView Customized Adapter :

@Override
public View getView(int i, View convertView, ViewGroup parent) {
    final MovieEntity feedItem=feedTrailersList.get(i);

    //LinearLayout Trailers_Linear=(LinearLayout) convertView.findViewById(R.id.Trailers_Linear);

    View view=convertView;
    if (view==null){
        view=LayoutInflater.from(getContext()).inflate(R.layout.trailer_list_item, parent,false);
    }
    TextView trailerName=(TextView)view.findViewById(R.id.trailer_name);
    trailerName.setText(feedItem.getTRAILER_NAME_STRING());
    trailerName.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent=new Intent(String.valueOf(Intent.FLAG_ACTIVITY_NEW_TASK));
            intent.setData(Uri.parse(feedItem.getTRAILER_KEY_STRING()));
            mContext.startActivity(intent);

        }
    });
 return view;
}

Here, i am trying to startActivity via my Context, as i am in a cutomized adapter class not in an activity, but it gives me this error titles :

ex: java.lang.reflect.InvocationTargetException
cause : android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

i was using Intent intent=new Intent(Intent.ACTION_VIEW); flag, and tried Intent intent=new Intent(String.valueOf(Intent.FLAG_ACTIVITY_NEW_TASK)); after it displayed this exception.

Can anybody tell my what does this exception refers to, your aid is completely, and respectively appreciated. Thanks in advance.


Solution

  • This is my block of current Intent Code now, and it's working

    Intent intent=new Intent(); 
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);     
    intent.setData(Uri.parse(feedItem.getTRAILER_KEY_STRING())); 
    getContext().startActivity(intent);