فيديو المحاضرة
فيديو المحاضرة
بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.
رسوم متحركة
أمثلة كود
أمثلة قصيرة وبسيطة
كل مثال وراه زرار «شغّل خطوة بخطوة»: بيعلّم على السطر اللي بيتنفّذ ويطبع الناتج زي ما بيتنفّذ بالظبط. ده شرح تنفيذ الكود سطر بسطر، مش مترجم حقيقي جوه الصفحة.
المثال ١: أول 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
System.out.println("Applications");
System.out.println("Application framework");
System.out.println("Android runtime");
System.out.println("Native libraries");
System.out.println("Linux kernel");
Expected output
Applications Application framework Android runtime Native libraries Linux kernel
التمرين 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
int[] api = {3, 4, 21, 23, 28};
int old = 0;
for (int i = 0; i < api.length; i++) {
if (api[i] < 21) old++;
}
System.out.println(old);
Expected output
2
مشروع صغير في آخر المحاضرة
جدول إصدارات 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
الخطوات
- خد التلات مصفوفات: الاسم، رقم الإصدار، ومستوى API.
- اطبع كل إصدار في سطر: الاسم والرقم ومستوى API.
- عدّ الإصدارات اللي مستوى API بتاعها 23 أو أحدث.
- اطبع العدد في آخر سطر. المتوقع تحت.
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
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;
for (int i = 0; i < names.length; i++) {
System.out.println(names[i] + " " + versions[i] + " API " + api[i]);
if (api[i] >= 23) modern++;
}
System.out.println("API 23 or newer: " + modern);
Expected output
Cupcake 1.5 API 3 Donut 1.6 API 4 Lollipop 5.0 API 21 Marshmallow 6.0 API 23 Pie 9.0 API 28 API 23 or newer: 2
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).