1

I'm having issues with understanding which activity launched my adapter. Both activities request the adapter pretty much the same so I thought using the same adapter for both of the recyclerViews in the 2 activities. For some reason, in the debugger I found that (obviously) the context.getApplicationInfo().name has value, but when I try to use "g" it equals null...

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

   private Context mContext;
   ...

   @Override
   public void onBindViewHolder(CustomCatalogAdapter.MyViewHolder holder, final int position) {
       ApplicationInfo applicationInfo = mContext.getApplicationInfo();
       String g = applicationInfo.name;
   }
}
shlomi
  • 35
  • 6

1 Answers1

1

Found the answer after searching Context's functions like getApplicationInfo() and getApplicationContext(). After looking at Alexander Lucas's answer:

https://stackoverflow.com/a/10641257/11388670

I understood that getContext() "Returns the context the view is currently running in. Usually the currently active Activity."

So, I backed up and tried functions on mContext, until I found out where was my adapter operating:

String myActivityName = mContext.getClass().getSimpleName();

That written above will give you your Activity name as you've named it at first when creating it. For for package name use instead:

mContext.getClass().getName()

shlomi
  • 35
  • 6