‘setHasOptionsMenu(Boolean): Unit’ is deprecated. Deprecated in Java

From the Developer documentation, this can be achieved by the following: /** * Using the addMenuProvider() API directly in your Activity **/ class ExampleActivity : ComponentActivity(R.layout.activity_example) { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Add menu items without overriding methods in the Activity addMenuProvider(object : MenuProvider { override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { // … Read more

Fragment inner class should be static

Non static inner classes do hold a reference to their parent classes. The problem with making a Fragment inner class non-static is that you always hold a reference to the Activity. The GarbageCollector cannot collect your Activity. So you can ‘leak’ the Activity if for example the orientation changes. Because the Fragment might still live … Read more

Fragment vs. Custom View in Android

Fragment can be used in different scenarios but most used are: wrapper around a view headless fragment – i.e. no view => not very helpful in general but can be used retainable fragment – can be any of above. By using Fragment.setRetainInstance(true) you can bypass Fragment.onDestroy(), i.e. can keep fragment data on configuration changes but … Read more

FragmentContainerView as NavHostFragment

Due to this bug-report: https://issuetracker.google.com/issues/142847973 This is the only way (currently): val navHostFragment = supportFragmentManager .findFragmentById(R.id.my_nav_host_fragment) as NavHostFragment val navController = navHostFragment.navController (Java): NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager() .findFragmentById(R.id.my_nav_host_fragment); NavController navController = navHostFragment.getNavController();

android.content.Context.getPackageName()’ on a null object reference

I have found the mistake what I did. We need to get the activity instance from the override method OnAttach() For example, public MainActivity activity; @Override public void onAttach(Activity activity){ this.activity = activity; } Then pass the activity as context as following. Intent mIntent = new Intent(activity, MusicHome.class);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)