Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1
Default resources

mReportButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_TEXT, getCrimeReport());
i.putExtra(Intent.EXTRA_SUBJECT,
getString(R.string.crime_report_subject));
i = Intent.createChooser(i, getString(R.string.send_report));
startActivity(i);
}
});


Run the app and press SEND CRIME REPORT to see the crash (Figure 18.6).


Figure 18.6  Missing English version of subject string


The moral of the story is this: Provide a default resource for each of your resources. Resources in
unqualified resource directories are your default resources. Default resources will be used if no match
for the current device configuration is found. Your app will misbehave if Android looks for a resource
and cannot find one that matches the device configuration.


(Leave crime_title_label and crime_report_subject commented out for now. You will be
reminded to uncomment both in a bit.)

Free download pdf