Example (Java): view.setBackground(R.drawable.minuPilt) textView.setText(R.string.minuTekst) Example (XML): <LinearLayout android:background="@drawable/minuPilt" <TextView android:text="@string/minuTekst"
have at least 1 Activity • Default Operating System Activity handling: if device is rotate = Activity destroyed • Each Activity needs to be defined in Manifest • Each Activity needs to extend *Activity.java base class public class MyActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); } }
with the user. Paused Activity is still visible but partially obscured, instance is running but might be killed by the system. Stopped Activity is not visible, instance is running but might be killed by the system. Killed Activity has been terminated by the system of by a call to its finish() method.
in which the user is interacting with an activity, or which has an service which is bound to such an activity. Also if a service is executing one of its lifecycle methods or a broadcast receiver which runs its onReceive() method. 1 Visible User is not interacting with the activity, but the activity is still (partially) visible or the application has a service which is used by a inactive but visible activity. 2 Service Application with a running service which does not qualify for 1 or 2. 3 Background Application with only stopped activities and without a service or executing receiver. Android keeps them in a least recent used (LRU) list and if requires terminates the one which was least used. 4 Empty Application without any active components. 5
rendering, writing to disc, network requests etc) Acquired: activity.getContext(); Activity extends Context meaning you can use Activity object where Context is needed (Java polymorphism) Example: meetodiNimi(Context c) Activity a = getActivity(); meetodiNimi(a);
has to extend *Fragment.java • Reusable module • Directly binded to Activity • Lifecycle really similar to Activity (onResume, onPause etc.) Adding to layout • Using object reference and FragmentTransaction in Java • Hardcode to layout XML file
new ExampleFragment(); FragmentTransaction transaction = getFragmentManager(). beginTransaction(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); // Commit the transaction transaction.commit();
Intent(this, ActivitySecond.class); startActivity(intent); IMPLICIT (ebamäärane) “Implicit Intents have not specified a component; instead, they must include enough information for the system to determine which of the available components is best to run for that intent.” Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage); startActivity(sendIntent);
of the installed apps to determine which ones can handle this kind of intent (an intent with the ACTION_SEND action and that carries "text/plain" data).”
to handle. With intent-filter, your application is saying to OS: I can handle this type of data, you can send it to me if you want <activity android:name="ShareActivity"> <intent-filter> <action android:name="android.intent.action.SEND"/> <category android:name="android.intent.category. DEFAULT"/> <data android:mimeType="text/plain"/> </intent-filter> </activity>
values/ strings.xml drawable/ Bitmap files layout/ XML files that define a user interface layout values/ XML files that contain simple values, • arrays.xml for resource arrays • colors.xml for color values • dimens.xml for dimension values. • strings.xml for string values. • styles.xml for styles.
for different type of configurations (landscape, portrait, high density screen, english UI language etc.) Example: in landscape show ListView + LinearLayout, in portrait only ListView res/ layout/ main.xml layout-land/ main.xml
fr etc. • Screen pixel density (dpi): ldpi, mdpi, hdpi, xhdpi etc. • Screen orientation: port, land • Platform Version (API level): v7, v14 Possible to combine: .../res/{type}-port-fr-ldpi/ Note: Qualifier is used in folder name ONLY