نقل البيانات باستخدام محوّلات المزامنة
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
ملاحظة: ننصح باستخدام WorkManager
كحلّ مقترَح لمعظم حالات استخدام المعالجة في الخلفية. يُرجى الرجوع إلى
دليل المعالجة في الخلفية لمعرفة الحلّ الأنسب لك.
يمكن أن تؤدي مزامنة البيانات بين جهاز Android وخوادم الويب إلى جعل التطبيق
أكثر فائدة وجاذبية للمستخدمين. على سبيل المثال، يؤدي نقل البيانات إلى خادم ويب إلى إنشاء نسخة احتياطية مفيدة، كما أنّ نقل البيانات من الخادم يجعلها متاحة للمستخدم حتى عندما يكون الجهاز غير متصل بالإنترنت. في بعض الحالات، قد يجد المستخدمون أنّه من الأسهل إدخال بياناتهم
وتعديلها في واجهة ويب، ثم تكون لديهم هذه البيانات على أجهزتهم، أو قد يريدون
جمع البيانات بمرور الوقت ثم تحميلها إلى مساحة تخزين مركزية.
ومع أنّه يمكنك تصميم نظامك الخاص لإجراء عمليات نقل البيانات في تطبيقك، عليك
التفكير في استخدام إطار عمل محوّل المزامنة من Android. يساعد إطار العمل هذا في إدارة عمليات نقل البيانات وبرمجتها، وتنسيق عمليات المزامنة بين التطبيقات المختلفة. عند استخدام
إطار العمل هذا، يمكنك الاستفادة من العديد من الميزات غير المتوفرة لحيل
نقل البيانات التي تصمّمها بنفسك:
-
بنية مكوّنة إضافية
-
تسمح لك بإضافة رمز نقل البيانات إلى النظام في شكل مكوّنات يمكن طلبها.
-
التنفيذ المبرمَج
-
يتيح لك نقل البيانات بشكل مبرمَج استنادًا إلى مجموعة من المعايير، بما في ذلك تغييرات البيانات
أو الوقت المنقضي أو الوقت من اليوم. بالإضافة إلى ذلك، يضيف النظام عمليات النقل التي لا يمكن
تشغيلها إلى قائمة الانتظار ويجريها إن أمكن.
-
التحقّق التلقائي من الشبكة
-
لا يجري النظام نقل البيانات إلا عندما يكون الجهاز متصلاً بالشبكة.
-
تحسين أداء البطارية
-
يسمح لك هذا الخيار بتجميع جميع مهام نقل البيانات الخاصة بتطبيقك في مكان واحد، بحيث
تعمل جميعها في الوقت نفسه. ويتم أيضًا تحديد موعد لنقل البيانات بالتزامن مع عمليات نقل البيانات من تطبيقات أخرى. تقلل هذه العوامل عدد المرات التي يجب على النظام
فيها تشغيل الشبكة، ما يقلّل من استخدام البطارية.
-
إدارة الحساب والمصادقة
-
إذا كان تطبيقك يتطلب بيانات اعتماد المستخدم أو تسجيل الدخول إلى الخادم، يمكنك اختياريًا دمج إدارة الحساب والمصادقة في نقل البيانات.
توضِّح لك هذه الفئة كيفية إنشاء محوِّل المزامنة وService
المرتبط الذي
يلتف حوله، وكيفية توفير المكوّنات الأخرى التي تساعدك في توصيل محوِّل المزامنة بإطار العمل، وكيفية تشغيل محوِّل المزامنة بطُرق مختلفة.
ملاحظة: تعمل محوّلات المزامنة بشكل غير متزامن، لذا يجب استخدامها مع توقّع أنّها تنقل البيانات بانتظام وبفعالية، ولكن ليس على الفور. إذا كنت تريد نقل البيانات في الوقت الفعلي، يجب إجراء ذلك من خلال AsyncTask
أو IntentService
.
دروس
-
إنشاء برنامج مصادقة للكعب
-
تعرَّف على كيفية إضافة مكوّن معالجة الحساب الذي يتوقعه إطار عمل محوِّل المزامنة
أن يكون جزءًا من تطبيقك. يوضّح لك هذا الدرس كيفية إنشاء مكوِّن مصادقة للرمز التبسيطي لتبسيطه.
-
إنشاء موفّر محتوى
-
تعرَّف على كيفية إضافة مكوِّن موفّر محتوى يتوقع أن يكون إطار عمل محوّل المزامنة
جزءًا من تطبيقك. يفترض هذا الدرس أن تطبيقك لا يستخدم موفّر محتوى، لذلك
يوضّح لك كيفية إضافة عنصر كعب. إذا كان تطبيقك يتضمّن موفِّر محتوى،
يمكنك تخطي هذا الدرس.
-
إنشاء محوِّل مزامنة
-
تعرَّف على طريقة تضمين رمز نقل البيانات في مكوِّن يمكن لإطار عمل محوّل المزامنة
تشغيله تلقائيًا.
-
تشغيل محوّل مزامنة
-
تعرَّف على كيفية تشغيل عمليات نقل البيانات وجدولتها باستخدام إطار عمل محوّل المزامنة.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Transfer data using sync adapters\n\n**Note:** We recommended [WorkManager](/topic/libraries/architecture/workmanager)\nas the recommended solution for most background processing use cases. Please reference the\n[background processing guide](/guide/background) to learn which solution works best for you.\n\n\nSynchronizing data between an Android device and web servers can make your application\nsignificantly more useful and compelling for your users. For example, transferring data to a web\nserver makes a useful backup, and transferring data from a server makes it available to the user\neven when the device is offline. In some cases, users may find it easier to enter and edit their\ndata in a web interface and then have that data available on their device, or they may want to\ncollect data over time and then upload it to a central storage area.\n\n\nAlthough you can design your own system for doing data transfers in your app, you should\nconsider using Android's sync adapter framework. This framework helps manage and automate data\ntransfers, and coordinates synchronization operations across different apps. When you use\nthis framework, you can take advantage of several features that aren't available to data\ntransfer schemes you design yourself:\n\n\nPlug-in architecture\n:\n Allows you to add data transfer code to the system in the form of callable components.\n\n\nAutomated execution\n:\n Allows you to automate data transfer based on a variety of criteria, including data changes,\n elapsed time, or time of day. In addition, the system adds transfers that are unable to\n run to a queue, and runs them when possible.\n\n\nAutomated network checking\n:\n The system only runs your data transfer when the device has network connectivity.\n\n\nImproved battery performance\n:\n Allows you to centralize all of your app's data transfer tasks in one place, so that they\n all run at the same time. Your data transfer is also scheduled in conjunction with data\n transfers from other apps. These factors reduce the number of times the system has to\n switch on the network, which reduces battery usage.\n\n\nAccount management and authentication\n:\n If your app requires user credentials or server login, you can optionally\n integrate account management and authentication into your data transfer.\n\n\nThis class shows you how to create a sync adapter and the bound [Service](/reference/android/app/Service) that\nwraps it, how to provide the other components that help you plug the sync adapter into the\nframework, and how to run the sync adapter to run in various ways.\n\n\n**Note:** Sync adapters run asynchronously, so you should use them with the\nexpectation that they transfer data regularly and efficiently, but not instantaneously. If\nyou need to do real-time data transfer, you should do it in an [AsyncTask](/reference/android/os/AsyncTask) or\nan [IntentService](/reference/android/app/IntentService).\n\nLessons\n-------\n\n\n**[Create a stub authenticator](/training/sync-adapters/creating-authenticator)**\n:\n Learn how to add an account-handling component that the sync adapter framework expects to be\n part of your app. This lesson shows you how to create a stub authentication component for\n simplicity.\n\n\n**[Create a stub content provider](/training/sync-adapters/creating-stub-provider)**\n:\n Learn how to add a content provider component that the sync adapter framework expects to be\n part of your app. This lesson assumes that your app doesn't use a content provider, so it\n shows you how to add a stub component. If you have a content provider already in your app,\n you can skip this lesson.\n\n\n**[Create a sync adapter](/training/sync-adapters/creating-sync-adapter)**\n:\n Learn how to encapsulate your data transfer code in a component that the sync\n adapter framework can run automatically.\n\n\n**[Run a sync adapter](/training/sync-adapters/running-sync-adapter)**\n:\n Learn how to trigger and schedule data transfers using the sync adapter framework."]]