In any Android user interface is displayed via an activity. In Android app development team, we may have to face so many types of situations where we require to switch between one activity (Screen/view) to other. Let us discuss about switching from one point to other via swipe and sending data to the activities.
Here is the code for handling activities. Let us assume Activity class name is SecondScreen.java
Opening New Activity
To open new activity following startActivity () or startActivityForResult () method is used.
Sending parameter to new Activity
To send parameter to the newly created activity putExtra () method is used.
Now, I will show you the how to use slide library to embed the swipe feature that will convert into an activity. Let us discuss each of them in details. In activity 2nd we can swipe it off the screen and also can able to slide back to keep the activity opened. There is a open button where we can open the slide and there is unlock button also to keep unlock the slide. When swipe off the screen the activity gets closed. For all of the above process, let us clear it by a simple example. As we have already discussed, there are two buttons in the activity named as Lock and Unlock button. When we click any of the button to call lock slide or unlock slide, method that is right now above empty and in our main activity. Here, we have one open activity button which when we clicked open the second activity.
Now, we have created a second style with opening angle bracket style and we call it and write it in separate file called
Now, let us discuss unlock file coding-
Receiving parameter on new Activity
To receive parameter on new created activity getStringExtra () method is used.
Open new Activity and follow result
In most of the situations, we can expect some data from newly created activity. In those situations, startActivityForResult () method is used. And once this new activity is closed then we should have to use onActivityResult () method to read the result.