Start an activity from a fragment

mFragmentFavorite in your code is a FragmentActivity which is not the same thing as a Fragment. That’s why you’re getting the type mismatch. Also, you should never call new on an Activity as that is not the proper way to start one. If you want to start a new instance of mFragmentFavorite, you can do so via an Intent. From a Fragment: From an Activity If you … Read more

Why this line xmlns:android=”http://schemas.android.com/apk/res/android” must be the first in the layout xml file?

In XML, xmlns declares a Namespace. In fact, when you do: Instead of calling android:id, the xml will use http://schemas.android.com/apk/res/android:id to be unique. Generally this page doesn’t exist (it’s a URI, not a URL), but sometimes it is a URL that explains the used namespace. The namespace has pretty much the same uses as the package name in … Read more

onSaveInstanceState () and onRestoreInstanceState ()

Usually you restore your state in onCreate(). It is possible to restore it in onRestoreInstanceState() as well, but not very common. (onRestoreInstanceState() is called after onStart(), whereas onCreate() is called before onStart(). Use the put methods to store values in onSaveInstanceState(): And restore the values in onCreate():

What is the meaning of android.intent.action.MAIN?

android.intent.action.MAIN means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created. From the docs Also,from here Activity Action Start as a main entry point, does not expect to receive data. android.intent.category.DEFAULT is mainly used for implicit intents. If your activity wishes to be started by an implicit intent … Read more

How to pass an object from one activity to another on Android

One option could be letting your custom class implement the Serializable interface and then you can pass object instances in the intent extra using the putExtra(Serializable..) variant of the Intent#putExtra() method. Pseudocode: Note: Make sure each nested class of your main custom class has implemented Serializable interface to avoid any serialization exceptions. For example: