كل المقررات

الرئيسية / مقرر تطبيقات الموبايل / الفصل 2 الجزء 1

الفصل 2 (الجزء 1): Introduction to Android

What Android is, where it came from, and how its stack is built

على طول: إيه Android، قصته، والطبقات اللي بيمشي عليها التطبيق.

فيديو المحاضرة

فيديو المحاضرة

بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.

رسوم متحركة

طبقات نظام Android

أمثلة كود

أمثلة قصيرة وبسيطة

كل مثال وراه زرار «شغّل خطوة بخطوة»: بيعلّم على السطر اللي بيتنفّذ ويطبع الناتج زي ما بيتنفّذ بالظبط. ده شرح تنفيذ الكود سطر بسطر، مش مترجم حقيقي جوه الصفحة.

المثال ١: أول Activity

public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        Log.d("MainActivity", "onCreate ran");    }}

    

المثال ٢: Intent بيطلب شاشة تانية

Intent i = new Intent(MainActivity.this, SecondActivity.class);i.putExtra("name", "Android");Log.d("MainActivity", "starting " + i.getComponent().getClassName());startActivity(i);

    

المثال ٣: صلاحية محتاجة موافقة

if (checkSelfPermission(Manifest.permission.CAMERA)        != PackageManager.PERMISSION_GRANTED) {    requestPermissions(new String[]{Manifest.permission.CAMERA}, 1);    Log.d("MainActivity", "asked the user for the camera");} else {    Log.d("MainActivity", "camera already allowed");}

    

اختبار قصير

اختبر فهمك

1. Android is built on which kernel?

2. Which company did Google buy in 2005 to get Android?

3. Which part actually runs your app's code?

4. In the stack, the application framework sits:

5. What replaced Dalvik?

تمارين

جرّب بإيدك

التمرين 1

اطبع أجزاء النظام الخمسة من فوق لتحت، كل جزء في سطر.

Print the five parts of the stack from top to bottom, one per line.

Starter code:

// TODO: five System.out.println lines, top to bottom

التمرين 2

عندك جدول إصدارات ومستوى API. اطبع عدد الإصدارات اللي مستوى API بتاعها أقل من 21.

You have a table of versions with API levels. Print how many have an API level below 21.

Starter code:

int[] api = {3, 4, 21, 23, 28};int old = 0;// TODO: count the values below 21 and print the count

مشروع صغير في آخر المحاضرة

جدول إصدارات Android

الداتا: android-versions: our own table of five versions with release number and API level.

License / source: Our own sample table; Android API level reference by Google (link only). Reference page

الخطوات

  1. خد التلات مصفوفات: الاسم، رقم الإصدار، ومستوى API.
  2. اطبع كل إصدار في سطر: الاسم والرقم ومستوى API.
  3. عدّ الإصدارات اللي مستوى API بتاعها 23 أو أحدث.
  4. اطبع العدد في آخر سطر. المتوقع تحت.

Starter code:

String[] names = {"Cupcake", "Donut", "Lollipop", "Marshmallow", "Pie"};double[] versions = {1.5, 1.6, 5.0, 6.0, 9.0};int[] api = {3, 4, 21, 23, 28};int modern = 0;// TODO: loop, print each row, count api >= 23// TODO: print "API 23 or newer: " + modern

Credits: the topic order follows the course notes "Mobile Application Development 1" by Dr. Muhammad Kashif Saeed (Applied College, Muhayil, King Khalid University), shared by the course owner. The explanations, diagrams, data and code in this lecture are our own; we copy nothing from the notes. Extra reference: Android developer documentation: app fundamentals and the Android platform (developer.android.com).