Category : android-context

I have a BackStack in the project, to make the transition from fragment to fragment I use the following public void showFragment(@NonNull Fragment fragment) { showFragment(fragment, true); } public void showFragment(@NonNull Fragment fragment, boolean addToBackStack) { if (curFragment != null && addToBackStack) { pushFragmentToBackStack(curTabId, curFragment); } replaceFragment(fragment); } private void replaceFragment(@NonNull Fragment fragment) { FragmentManager ..

Read more

I am trying to create an object of fingerline(class) in drawline(activity).The fingerline takes the context of MainActivity(activity).I get ClassCastException showing that Process: com.example.caddrawingtool, PID: 11405 java.lang.RuntimeException: Unable to instantiate application com.example.caddrawingtool.MainActivity: java.lang.ClassCastException: com.example.caddrawingtool.MainActivity cannot be cast to android.app.Application at android.app.LoadedApk.makeApplication(LoadedApk.java:1226) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6504) at android.app.ActivityThread.access$1400(ActivityThread.java:229) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1892) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7436) at java.lang.reflect.Method.invoke(Native Method) ..

Read more

I’m using SharedPrefernces for getting the user/logging out the user but I keep getting the error "Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag". the logout method is used to clear the stored data from the device. This is what i’m using for the logout method: logout_nav.setOnClickListener(new View.OnClickListener() { @Override public ..

Read more

Pre-History I have a ViewPager2 with TabLayout that switches fragments made up of lists (recyclerView) of objects. The task is to make detailed information about the object open on item (viewHolder) click. Problem To do that, i need to somehow get a activity context. But the context is null, because the fragments are inserted into ..

Read more