Logging in Android

Logging brings some light into the darkness of your code. If you are new to logging please have a look at Log4j2 for Kotlin Import import android.util.Log Tag class MainActivity : AppCompatActivity() { companion object { const val TAG = “MainActivity” } Log statement override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Log.d(TAG, “onCreate”) } Logcat Further…

Network Requests with Volley

Consider Volley a 2.0 version of Android Asynchronous Http Client. A major advantage of Volley over ASyncTask is that you can do multiple requests simultaneously without the overhead of thread management. Gradle Add implementation ‘com.android.volley:volley:1.2.1’ to your module gradle dependencies. Basic Anatomy of a Volley Request val queue = Volley.newRequestQueue(context) val stringRequest = StringRequest( Request.Method.GET,…

Localization of Android Apps

If you want to add another language for your app do the following Create a new folder e.g. app/src/main/res/values-de Add strings.xml into this folder Translate the content The cool thing about translation in android is that you can do it incrementally: when there is no translation for a string resource in a locale Android will…

Passing data between fragments using SafeArgs

App Gradle plugins { id ‘androidx.navigation.safeargs.kotlin Project Gradle dependencies { classpath “androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5″ nav_graph.xml <fragment> <action android:id=”@+id/action_SecondFragment_to_FirstFragment” app:destination=”@id/FirstFragment” /> <argument android:name=”myArg” app:argType=”integer” /> FirstFragment import com.example.codelabsfirstappwithkotlin.databinding.FragmentFirstBinding val action = FirstFragmentDirections.actionFirstFragmentToSecondFragment(currentCount) findNavController().navigate(action) SecondFragment import androidx.navigation.fragment.navArgs val args: SecondFragmentArgs by navArgs() val count = args.myArg

How to use an AVAudioPlayer in iOS with Swift 5

If you write an app that should play sound here is a snippet for you import AVFoundation var player: AVAudioPlayer? let url = Bundle.main.path(forResource: “richtig”, ofType: “wav”) do { try AVAudioSession.sharedInstance().setMode(.default) try AVAudioSession.sharedInstance().setActive(true, options: .notifyOthersOnDeactivation) guard let url = url else { return } player = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: url)) } catch { print(“Something went…