Bound service: binding to a service, what is the function that needs to be implemented in service class?
Options
1) onCreate()
2) onBind() & onUnbind()
3) ServiceConnectionListener in client side.
4) all above 3 are required
start a service from activity and close activity, what will happen to that service, will it be alive or dead?
Options
1) service will also be killed
2) service will be alive for some time, and will be killed by android garbage collector.
3) service will run for ever, no body can stop it now, and it leaks memory.
4) service will be keep running in the background but it can stop itself when the work given to it is done. Or others also can kill that service using stopService(), or android also can kill the service forcefully in case of low memory scenarios.
What does the flag FLAG_ACTIVITY_SINGLE_INSTANCE do here?
Intent i = new Intent();
i.setAction("com.android.MYACTION");
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_INSTANCE);
startActivity(i);
Options
1) It will start a new activity with matching intent filter, in a new task always.
2) It will start a new activity with matching intent filter, in a new task only if that corresponding task is not in memory now.
3) It will start a new activity with matching intent filter, in old task always. here old task means task in which the current activity is running which has started new activity.
4) This will start new activity in a new task, where only this activity will be there in that task and no other components. if at all new components are launched from this new activity, they will be launched in a different task.
What does the flag FLAG_ACTIVITY_NEW_TASK do here?
Intent i = new Intent();
i.setAction("com.android.MYACTION");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Options
1) This will start a new activity in a new task, where only this activity will be there in that task and no other components. if at all new components are launched from this new activity, they will be launched in a different task.
2) It will start a new activity with matching intent filter, in old task always, here old task means task in which the current activity is running which has started new activity.
3) It will start a new activity with matching intent filter, in a new task only if that corresponding task is not in memory now.
4) It will start a new activity with matching intent filter, in a new task always.
What will happen if an activity is started with implicit intent, and there is no matching intent-filter?
Options
1) Nothing will happen, but it will not launch any new screen.
2) Nothing will happen, some how how it launches target component
3) It will throw run time exception - activityNotFoundException, and crashes if it is handled properly.
4) Compile time error.
What will happen if there is no action in an implicit intent, will it trigger any component?
Options
1) Will pass the action test if intent-filter has at least one action.
2) Will pass the action test if intent-filter also doesn't have any action.
3) Will pass the test if intent is explicit. In case of explicit intent it will test for intent resolution.
4) Will pass the action test only if intent has at least one action.