//get a string resource with ID "hello_world" String greeting = getString(R.string.hello_world); //display the greeting in a text view TextView textView = findViewById(R.id.my_text_view); textView.setText(greeting);
//get a string resource with ID "error_message" and format it with a variable String errorMessage = getString(R.string.error_message, errorCode); //display the error message in a dialog box AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(errorMessage) .setTitle(R.string.error_title) .setPositiveButton(R.string.ok_button, null) .show();In this example, the getString() method is used to retrieve a string with the ID "error_message" and format it with a variable called "errorCode". The formatted string is then displayed in an alert dialog box with a title and an "OK" button. The android.app package library provides fundamental application components, such as Activities, Services, and Broadcast Receivers, that are necessary for building Android apps.