Posts

Showing posts with the label Android

Quick Pop-up with Context Menu in Android

During the creation of an android application, sometimes it is required to show a popup menu to get quick action from the user. For example, when a user long presses on any view we have to show some options and the user is able to pick one of them, and based on the selection we have to perform some tasks. To show this kind of pop-up android provides context menu API. Let's check how we can use it with an example. The context  menu provides an ability to bind any view with it. You can also change the subject of the menu if it is required.   To show a pop-up menu first, you have to register that view with registerForContextMenu(). For now, Don't get confused with the method. Later we are going to check how to use it in the application but for now, just remember that to show the context menu we have to register it with the above method. Add Items to the Menu To add the items in the menu you have to override the onCreateContextMenu in the activity shown in the example below : ...

Which one to use Activity Context Or Application Context?

Many android developers get confused between activity and application context. Some types we are getting confused about which context we have to use and make the android resources a more efficient way. As we know two types of context application and activity context. Both the context are extending the super-class context. Activity Context It represents the current activity information and also depends upon the activity life cycle. If you want to perform some operation based on activity life span then we are using it. Mostly in the application when we need to start a new activity or show dialog than we can use this kind of context.  Application Context   The life span of this context is based on the application state. It does not depend upon the activity life span, So if the activity is killed or destroyed then it does not affect the application context. The context has become available when you are launching the application and have the value until the application not ge...

Animation with the Motion Layout in Android

As a developer, we know that the animation is pretty hard to manage and if we don't handle it properly it will hang the UI. Sometimes it will twice to thrice time than the UI design. The proper animation makes your app more attractive. To create the animation very easy and attractive way the android introduces a new Motion Layout. The key feature of this layout is you do not have to write a single line of code to perform the animation. Is it Great? Like me, you also want to add animation in the project but due to timeline or more code we avoiding to add it. So from now, you can add the animation with less and easily maintain code. MotionLayout is a layout class that extends from ConstraintLayout . MotionLayout has all the features of ConstraintLayout. Motion layout is providing the functionality to animate the view on interactive animations. I know we have talked a lot about this new layout and you want to try it. Let's check it with a simple example first. In t his e...