0

I am new android developer and I am building a App in SDK 28 with minSdkVersion 22.

Using a codefragment from another App I now get the warning message: 'android.content.intent' is deprecated.

I found some threads regarding the usage of getIntent() but I am creating a new intent in my case in a RecyclerViewAdapter to open a new Activity.

You can check out my Code or Screenshot below:

package com.example.chris.projectartifact.bb_Items;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.chris.projectartifact.R;

import java.util.List;

public class ItemRViewAdapter extends RecyclerView.Adapter<ItemRViewAdapter.MyViewHolder> {

    private Context mContext;
    private List<Items> mData;

    public ItemRViewAdapter(Context mContext, List<Items> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }


    @Override
    public ItemRViewAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        LayoutInflater mInflater = LayoutInflater.from(mContext); //TODO what does that?
        view = mInflater.inflate(R.layout.layout_cardview_cards,parent,false);
        return new ItemRViewAdapter.MyViewHolder(view);
    }

    public void onBindViewHolder(ItemRViewAdapter.MyViewHolder holder, final int position) {
        holder.ivSpell_img.setImageResource(mData.get(position).getItemImage());
        holder.tvSpell_title.setText(mData.get(position).getItemTitle());

        holder.cardView_spells_id.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // This is where my problem is..!
                Intent intent = new Intent(mContext, itemClickable.class);     
                intent.putExtra("itemName", mData.get(position).getItemTitle());
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder{
        TextView tvSpell_title;
        CardView cardView_spells_id;
        ImageView ivSpell_img;

        public MyViewHolder(View itemView) {
            super(itemView);

            tvSpell_title = itemView.findViewById(R.id.tvSpell_title);
            ivSpell_img = itemView.findViewById(R.id.ivSpell_img);

            cardView_spells_id = itemView.findViewById(R.id.cardView_spells_id);
        }
    }

}

Screenshot: intent is strikethrough

Maybe you can help me with that!

Edit new Screenshot where I fixed the itemClickable not recognized Issue. Fixed itemClickable.class

Thanks! CG

mrmeaaan
  • 670
  • 1
  • 6
  • 18
  • 2
    In documentation, I can't find anywhere saying intent as deprecated – Vivek Mishra Oct 15 '18 at 04:22
  • hey @VivekMishra. Thanks for checking the Documentation. Do you have any idea where this could come from then? I copied this class from a sdk 26 programme into a sdk 28 programme. Could this make an issue? – mrmeaaan Oct 15 '18 at 04:46
  • may be this is because it cannot find itemClickable.class – Vishal Oct 15 '18 at 04:52
  • Check your imports too. – Vivek Mishra Oct 15 '18 at 05:00
  • No, it is not because of itemClickable. Changed that obviously. import com.example.chris.projectartifact.R; import android.content.Context; import android.content.Intent; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import java.util.List; That are my imports. I dont know how to edit them properly, though :s – mrmeaaan Oct 15 '18 at 06:05
  • Could you try placing your cursor on the striked-out "Intent" text, and pressing Ctrl+F1 to see more details? That message is usually helpful. – shriakhilc Oct 15 '18 at 06:25
  • @TheGamer007 did that :) – mrmeaaan Oct 15 '18 at 10:44
  • This is unusual. What kind of class is `itemClickable`? And have you tried to "Invalidate caches / Restart" from the File menu? This seems like a false positive, so maybe that would fix it. – shriakhilc Oct 15 '18 at 11:24
  • @TheGamer007 I tried this aswell and sadly that did not help. itemClickable is Activity, therefore I would say a basic java class (?, not sure what it should be else). And the warning is happening in the Adapter of my RecyclerView. It works as expected by the way, but the issue is still not fixed. – mrmeaaan Oct 15 '18 at 12:00

1 Answers1

0

The Intent is not deprecated the problem is with your itemClickable.class because it is not recognized.

Either you have somehow enabled extra warnings that identify Intent as deprecated or something is really stack at your machine.

enter image description here

madlymad
  • 6,367
  • 6
  • 37
  • 68
  • Sorry Sir. This is not the issue. To let me believe you I will add a new screenshot where I erased that issue. – mrmeaaan Oct 15 '18 at 10:42
  • Added a screenshot of my Android Studio 3.2.1. I would suggest a restart (Android Studio/PC), project cleanup, reset of Android Studio to default settings! – madlymad Oct 15 '18 at 19:35
  • Hey. I did that but it did not change the outcome. Can you imagine that it has something to do with me using a RecyclerView.Adapter as an extension? – mrmeaaan Oct 23 '18 at 02:32