Created
November 2, 2022 08:01
-
-
Save alokomkar/b80f17c89e3dd4b4f43cd3fe24e80694 to your computer and use it in GitHub Desktop.
Step 5 : HomeFragment with start and stop service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.content.Intent | |
| import android.os.Bundle | |
| import android.view.LayoutInflater | |
| import android.view.View | |
| import android.view.ViewGroup | |
| import androidx.appcompat.widget.AppCompatButton | |
| import androidx.fragment.app.Fragment | |
| import com.alokomkar.javacollections.R | |
| import com.alokomkar.service.AudioLoopService | |
| class HomeFragment: Fragment() { | |
| override fun onCreateView( | |
| inflater: LayoutInflater, | |
| container: ViewGroup?, | |
| savedInstanceState: Bundle? | |
| ): View? { | |
| return inflater.inflate(R.layout.fragment_home, container, false) | |
| } | |
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
| super.onViewCreated(view, savedInstanceState) | |
| view.apply { | |
| findViewById<AppCompatButton>(R.id.startButton).setOnClickListener { | |
| context.startService(Intent( | |
| context, | |
| AudioLoopService::class.java | |
| )) | |
| } | |
| findViewById<AppCompatButton>(R.id.stopButton).setOnClickListener { | |
| context.stopService(Intent( | |
| context, | |
| AudioLoopService::class.java | |
| )) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment