Sometimes we pass context of an activity as a parameter to some other function and later we might want the activity too. So instead of passing the activity also to that function, we can get the activity from context itself. Method 1 You can get the activity from the context…
Normally when we launch new activity, it’s previous activities will be kept in a queue like a stack of activities. So if you want to kill all the previous activities, just follow these methods. Method 1 In API level 11 or greater, use FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK flag on Intent to…
If you want to dismiss the keypad manually through code, you can do that with the following methods Method 1 Call these lines on which EditText you want to dismiss the keypad.
Sometimes your android emulator might fails to connect eclipse DDMS tool and ask for adb to start manually. In that case you can start or stop the adb using the command prompt. Method 1 Open the cmd from Start ⇒ run ⇒ cmd and execute these commands. Before you execute…
If your activity class extends Activity, you can get application context using getApplicatoinContext(). But this method won’t be available when your Activity extends from Fragment. Method 1 When your activity extends Fragment, use getActivity () to get the context of the activity.
Invoking click event on all the views (Buttons, Layout etc.,) through code can be done so easily. Method 1 Call performClick() function on the view for which you want to perform click event
You can show and hide android views (layout, button, textview etc.,) at any time. You can also use animations like fadeOut or fadeIn to make it more beautiful while hiding and showing the views. Please refer Android Working with XML Animations if you want to add animations to view while…
Detecting android device hardware back button / soft back button press is very easy. But be careful while overriding the default back button action as it is not suggested to change the android default user experience. Method 1 Override the onBackPressed() method and take the action inside this function.