SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
Überleben im
FunklochOfflinefähige Apps für Android entwickeln
ChristianJanz( )@c_janz
christian.janz@bridging-it.de
Twitter: | E-Mail:
Slides:
Christian Janz
Consultantim Bereich SoftwareentwicklungJava/JEE bei
in MannheimBridging IT
Interesse: Architektur und Entwicklungvon
Geschäftsanwendungen mitHilfe moderner JavaFrameworks
@c_janz christian.janz@bridging-it.de
http://de.slideshare.net/cjanz
Agenda
Motivation
Lösungsidee
Architekturansatz
APIs im Einsatz: Sync Sample
Fazit
Motivation
1. Juli2013
Lösungsidee
Synchronisiere Daten und
speichere sie lokal auf dem
Gerät
Vorteile
App kann auch ohne aktive Datenverbindunggenutztwerden
Datenvolumen wird reduziert
Akkulaufzeitwird erhöht
Daten werden automatisch aktualisiert, wenn eine
Datenverbindungbesteht
Retrybeiabgebrochener Verbindung
"Nebenbei": Verbesserte Architektur
Architektur
"DevelopingAndroidREST Client Applications"
Architekturansatz für Android
Vortragvon VirgilDobjanschiauf der Google IO 2010
Quelle: Developing Android RESTClient Applications
SyncAdapter: Features
Beachten von Netzwerkverfügbarkeit
Synchronisation auch wenn App nichtläuft
Periodische Synchronisation
Warteschlage
Bündeln von Syncs: Gutfür Akkulaufzeit
Integration in globale Sync-Einstellungen
Integration in Account-Verwaltung
APIs im Einsatz:
Sync Sample
Vorgehen
Authenticator &Account
ContentProvider
RESTclient
SyncAdapter
UI
https://github.com/cjanz/android-sync-sample
Authenticator & Account
AuthenticatorService
Authenticator
LoginActivity
authenticator.xml
AndroidManifest.xml
authenticator.xml
<account-authenticator
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="de.bit.android.sample.account"
android:icon="@drawable/ic_launcher"
android:smallIcon="@drawable/ic_launcher"
android:label="@string/app_name"
/>
AndroidManifest.xml
<service
android:name="de.bit.android.syncsample.authenticator.AuthenticatorService">
<intent-filter>
<actionandroid:name="android.accounts.AccountAuthenticator"/>
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator"/>
</service>
<activity
android:name="de.bit.android.syncsample.authenticator.LoginActivity"
android:excludeFromRecents="true"
android:exported="true"
android:theme="@android:style/Theme.Holo">
</activity>
Demo: Authenticator &
Account
ContentProvider
TodoContentProvider
DatabaseHelper
TodoEntity
AndroidManifest.xml
TodoEntity
publicclassTodoEntity{
privateLongid;
privateLongserverId;
privateLongserverVersion;
privateLongconflictedServerVersion;
privateSyncStatesyncState=SyncState.NOOP;
privateStringtitle;
privateStringtext;
...(gettersandsetters)
}
REST client
publicclassTodoRestClient{
publicstaticList<TodoEntity>loadAllTodos()throwsIOException,JSONException;
publicstaticTodoEntitysaveTodo(TodoEntitytodoEntity)throwsIOException,JSONExceptio
publicstaticvoiddeleteTodo(TodoEntitytodoEntity)throwsIOException;
}
SyncAdapter
SyncService
SyncAdapter
syncadapter.xml
AndroidManifest.xml
syncadapter.xml
<?xmlversion="1.0"encoding="utf-8"?>
<sync-adapter
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="de.bit.android.sample.account"
android:contentAuthority="de.bit.android.syncsample.content"
android:supportsUploading="true"/>
AndroidManifest.xml
<serviceandroid:name="de.bit.android.syncsample.sync.SyncService">
<intent-filter>
<actionandroid:name="android.content.SyncAdapter"/>
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter"/>
</service>
Demo: Speichern der Daten
vom Backend
@Override
publicvoidonPerformSync(Accountaccount,Bundleextras,Stringauthority,
ContentProviderClientprovider,SyncResultsyncResult){
...
}
Periodische Synchronisation
privatevoidconfigureSync(Accountaccount){
ContentResolver.setIsSyncable(account,CONTENT_AUTHORITY,1);
ContentResolver.setSyncAutomatically(account,CONTENT_AUTHORITY,true);
Bundleparams=newBundle();
params.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED,false);
params.putBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY,false);
params.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL,false);
ContentResolver.addPeriodicSync(account,CONTENT_AUTHORITY,params,60);
ContentResolver.requestSync(account,CONTENT_AUTHORITY,params);
}
UI
MainActivity
activity_main.xml
todo_row.xml
EditTodoActivity
activity_edit_todo.xml
AndroidManifest.xml
Demo: Sync-Status anzeigen
@Override
protectedvoidonResume(){
super.onResume();
syncObserverHandle=ContentResolver.addStatusChangeListener(
SYNC_OBSERVER_TYPE_ACTIVE|SYNC_OBSERVER_TYPE_PENDING,this);
}
@Override
publicvoidonStatusChanged(intwhich){
runOnUiThread(newRunnable(){
@Override
publicvoidrun(){
booleanisSyncActive=ContentResolver.isSyncActive(account,
TodoContentProvider.AUTHORITY);
setProgressBarIndeterminateVisibility(isSyncActive);
}
});
}
Demo: Synchronisation
anstoßen
Bundleparams=newBundle();
params.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED,true);
params.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL,true);
ContentResolver.requestSync(account,TodoContentProvider.AUTHORITY,
params);
Demo: Automatisches Update
der UI
CursorLoader und ContentResolver.notifyChange(...)
Demo: Create, Update, Delete
Fazit
Offlinefähige Apps haben Vorteile
Offlinefähigkeitmuss nichtaufwändigsein
Android bietetgute Unterstützungdafür
Dokumentation nichtoptimal
Fehlerhandlingmuss beachtetwerden
Links
Transferring Data Using SyncAdapters | Android Developers
Slides: Android SyncAdapter | AlexTumanoff
Tutorial: Writeyour ownAndroid SyncAdapter | Udinic
SyncAdapter SampleApp| ChristianJanz

Mais conteúdo relacionado

Destaque

Destaque (18)

Encuesta Hinterlace Nov 2009
Encuesta Hinterlace Nov 2009Encuesta Hinterlace Nov 2009
Encuesta Hinterlace Nov 2009
 
Uso De Los Blogs En Las Bibliotecas Ut
Uso De Los Blogs En Las Bibliotecas UtUso De Los Blogs En Las Bibliotecas Ut
Uso De Los Blogs En Las Bibliotecas Ut
 
Enero2009
Enero2009Enero2009
Enero2009
 
Frases Para El Corazon
Frases Para El CorazonFrases Para El Corazon
Frases Para El Corazon
 
Por El Papa
Por El PapaPor El Papa
Por El Papa
 
Promo Curso Búsquedas Avanzadas
Promo Curso Búsquedas AvanzadasPromo Curso Búsquedas Avanzadas
Promo Curso Búsquedas Avanzadas
 
SHOPPING
SHOPPINGSHOPPING
SHOPPING
 
3 Umpire-System (Fortgeschrittene)
3 Umpire-System (Fortgeschrittene)3 Umpire-System (Fortgeschrittene)
3 Umpire-System (Fortgeschrittene)
 
Travesia Region Andina
Travesia Region AndinaTravesia Region Andina
Travesia Region Andina
 
Una ruta per Pedreguer. La pansa
Una ruta per Pedreguer. La pansaUna ruta per Pedreguer. La pansa
Una ruta per Pedreguer. La pansa
 
Präsentation kopie
Präsentation kopiePräsentation kopie
Präsentation kopie
 
El país en 360° (ENCUESTA)
El país en 360° (ENCUESTA)El país en 360° (ENCUESTA)
El país en 360° (ENCUESTA)
 
Der Montag liebt dich. #rp13
Der Montag liebt dich. #rp13Der Montag liebt dich. #rp13
Der Montag liebt dich. #rp13
 
Commons
CommonsCommons
Commons
 
Reservas mundiales de gas
Reservas mundiales de gasReservas mundiales de gas
Reservas mundiales de gas
 
Ost 1 10111 85
Ost 1 10111 85Ost 1 10111 85
Ost 1 10111 85
 
El EspíRitu Correcto Para Hacer Nuestra Mision_Plan Anual
El EspíRitu Correcto Para Hacer Nuestra Mision_Plan AnualEl EspíRitu Correcto Para Hacer Nuestra Mision_Plan Anual
El EspíRitu Correcto Para Hacer Nuestra Mision_Plan Anual
 
U09 Microsoft Access CreacióN De Formularios
U09  Microsoft Access CreacióN De FormulariosU09  Microsoft Access CreacióN De Formularios
U09 Microsoft Access CreacióN De Formularios
 

Semelhante a Offlinefähige Apps für Android entwickeln (Karlsruher Entwicklertag 2014)

Offlinefähige Apps für Android entwickeln (Google DevFest Karlsruhe 2013)
Offlinefähige Apps für Android entwickeln (Google DevFest Karlsruhe 2013)Offlinefähige Apps für Android entwickeln (Google DevFest Karlsruhe 2013)
Offlinefähige Apps für Android entwickeln (Google DevFest Karlsruhe 2013)Christian Janz
 
Push-Benachrichtigungen in SharePoint via SignalR
Push-Benachrichtigungen in SharePoint via SignalRPush-Benachrichtigungen in SharePoint via SignalR
Push-Benachrichtigungen in SharePoint via SignalRChristian Heindel
 
Developer Week 2019: Architekturen für .NET Core-Anwendungen
Developer Week 2019: Architekturen für .NET Core-AnwendungenDeveloper Week 2019: Architekturen für .NET Core-Anwendungen
Developer Week 2019: Architekturen für .NET Core-AnwendungenRobin Sedlaczek
 
Architectures for .Net Core Applications
Architectures for .Net Core ApplicationsArchitectures for .Net Core Applications
Architectures for .Net Core ApplicationsRobin Sedlaczek
 
.NET Core Architecture (UI)
.NET Core Architecture (UI).NET Core Architecture (UI)
.NET Core Architecture (UI)Robin Sedlaczek
 
Mobile App Entwicklung
Mobile App EntwicklungMobile App Entwicklung
Mobile App Entwicklungmediaman
 
Windows 8 Business-App-Entwicklung
Windows 8 Business-App-EntwicklungWindows 8 Business-App-Entwicklung
Windows 8 Business-App-EntwicklungMatthias Jauernig
 
Bautagebuch App für Android, iPhone und iPad
Bautagebuch App für Android, iPhone und iPadBautagebuch App für Android, iPhone und iPad
Bautagebuch App für Android, iPhone und iPadbauskript
 
LightSwitch und SQL Azure: Datengetriebene Anwendungen in Rekordzeit erstellen
LightSwitch und SQL Azure: Datengetriebene Anwendungen in Rekordzeit erstellenLightSwitch und SQL Azure: Datengetriebene Anwendungen in Rekordzeit erstellen
LightSwitch und SQL Azure: Datengetriebene Anwendungen in Rekordzeit erstellenAlexander Galkin
 
sones NoSQL GraphDatenbank für Bilderportale
sones NoSQL GraphDatenbank für Bilderportalesones NoSQL GraphDatenbank für Bilderportale
sones NoSQL GraphDatenbank für Bilderportalesones GmbH
 
My application as webdesigner and front-end developer
My application as webdesigner and front-end developerMy application as webdesigner and front-end developer
My application as webdesigner and front-end developerchristianschweinhardt
 
Migration von Aftersales Systemen auf eine Cloud Plattform
Migration von Aftersales Systemen auf eine Cloud PlattformMigration von Aftersales Systemen auf eine Cloud Plattform
Migration von Aftersales Systemen auf eine Cloud PlattformQAware GmbH
 
Software-Engineering in der Luft- und Raumfahrt mit Open-Source-Tools
Software-Engineering in der Luft- und Raumfahrt mit Open-Source-ToolsSoftware-Engineering in der Luft- und Raumfahrt mit Open-Source-Tools
Software-Engineering in der Luft- und Raumfahrt mit Open-Source-ToolsAndreas Schreiber
 
Dr. Ingo Laue - Microsoft Azure | Projekt-Erfahrungen
Dr. Ingo Laue - Microsoft  Azure | Projekt-ErfahrungenDr. Ingo Laue - Microsoft  Azure | Projekt-Erfahrungen
Dr. Ingo Laue - Microsoft Azure | Projekt-ErfahrungenCloudCamp Hamburg
 
DB Infrastructure Challenge - Team 4M
DB Infrastructure Challenge - Team 4MDB Infrastructure Challenge - Team 4M
DB Infrastructure Challenge - Team 4MDBHackathon
 
Automatisierte Generierung hybrider Apps für Mobile Devices
Automatisierte Generierung hybrider Apps für Mobile DevicesAutomatisierte Generierung hybrider Apps für Mobile Devices
Automatisierte Generierung hybrider Apps für Mobile DevicesJens Küsters
 
Microservices – die Architektur für Agile-Entwicklung?
Microservices – die Architektur für Agile-Entwicklung?Microservices – die Architektur für Agile-Entwicklung?
Microservices – die Architektur für Agile-Entwicklung?Christian Baranowski
 
IT-Ringvorlesung - Präsentation Unister
IT-Ringvorlesung - Präsentation UnisterIT-Ringvorlesung - Präsentation Unister
IT-Ringvorlesung - Präsentation UnisterEmpfehlungsbund
 
Responsive Webdesign Process
Responsive Webdesign ProcessResponsive Webdesign Process
Responsive Webdesign ProcessSven Wolfermann
 

Semelhante a Offlinefähige Apps für Android entwickeln (Karlsruher Entwicklertag 2014) (20)

Offlinefähige Apps für Android entwickeln (Google DevFest Karlsruhe 2013)
Offlinefähige Apps für Android entwickeln (Google DevFest Karlsruhe 2013)Offlinefähige Apps für Android entwickeln (Google DevFest Karlsruhe 2013)
Offlinefähige Apps für Android entwickeln (Google DevFest Karlsruhe 2013)
 
Push-Benachrichtigungen in SharePoint via SignalR
Push-Benachrichtigungen in SharePoint via SignalRPush-Benachrichtigungen in SharePoint via SignalR
Push-Benachrichtigungen in SharePoint via SignalR
 
Developer Week 2019: Architekturen für .NET Core-Anwendungen
Developer Week 2019: Architekturen für .NET Core-AnwendungenDeveloper Week 2019: Architekturen für .NET Core-Anwendungen
Developer Week 2019: Architekturen für .NET Core-Anwendungen
 
Architectures for .Net Core Applications
Architectures for .Net Core ApplicationsArchitectures for .Net Core Applications
Architectures for .Net Core Applications
 
.NET Core Architecture (UI)
.NET Core Architecture (UI).NET Core Architecture (UI)
.NET Core Architecture (UI)
 
Mobile App Entwicklung
Mobile App EntwicklungMobile App Entwicklung
Mobile App Entwicklung
 
Windows 8 Business-App-Entwicklung
Windows 8 Business-App-EntwicklungWindows 8 Business-App-Entwicklung
Windows 8 Business-App-Entwicklung
 
Bautagebuch App für Android, iPhone und iPad
Bautagebuch App für Android, iPhone und iPadBautagebuch App für Android, iPhone und iPad
Bautagebuch App für Android, iPhone und iPad
 
LightSwitch und SQL Azure: Datengetriebene Anwendungen in Rekordzeit erstellen
LightSwitch und SQL Azure: Datengetriebene Anwendungen in Rekordzeit erstellenLightSwitch und SQL Azure: Datengetriebene Anwendungen in Rekordzeit erstellen
LightSwitch und SQL Azure: Datengetriebene Anwendungen in Rekordzeit erstellen
 
sones NoSQL GraphDatenbank für Bilderportale
sones NoSQL GraphDatenbank für Bilderportalesones NoSQL GraphDatenbank für Bilderportale
sones NoSQL GraphDatenbank für Bilderportale
 
My application as webdesigner and front-end developer
My application as webdesigner and front-end developerMy application as webdesigner and front-end developer
My application as webdesigner and front-end developer
 
Migration von Aftersales Systemen auf eine Cloud Plattform
Migration von Aftersales Systemen auf eine Cloud PlattformMigration von Aftersales Systemen auf eine Cloud Plattform
Migration von Aftersales Systemen auf eine Cloud Plattform
 
Software-Engineering in der Luft- und Raumfahrt mit Open-Source-Tools
Software-Engineering in der Luft- und Raumfahrt mit Open-Source-ToolsSoftware-Engineering in der Luft- und Raumfahrt mit Open-Source-Tools
Software-Engineering in der Luft- und Raumfahrt mit Open-Source-Tools
 
Dr. Ingo Laue - Microsoft Azure | Projekt-Erfahrungen
Dr. Ingo Laue - Microsoft  Azure | Projekt-ErfahrungenDr. Ingo Laue - Microsoft  Azure | Projekt-Erfahrungen
Dr. Ingo Laue - Microsoft Azure | Projekt-Erfahrungen
 
Zertifizierter projektmanager verfügbar
Zertifizierter projektmanager verfügbarZertifizierter projektmanager verfügbar
Zertifizierter projektmanager verfügbar
 
DB Infrastructure Challenge - Team 4M
DB Infrastructure Challenge - Team 4MDB Infrastructure Challenge - Team 4M
DB Infrastructure Challenge - Team 4M
 
Automatisierte Generierung hybrider Apps für Mobile Devices
Automatisierte Generierung hybrider Apps für Mobile DevicesAutomatisierte Generierung hybrider Apps für Mobile Devices
Automatisierte Generierung hybrider Apps für Mobile Devices
 
Microservices – die Architektur für Agile-Entwicklung?
Microservices – die Architektur für Agile-Entwicklung?Microservices – die Architektur für Agile-Entwicklung?
Microservices – die Architektur für Agile-Entwicklung?
 
IT-Ringvorlesung - Präsentation Unister
IT-Ringvorlesung - Präsentation UnisterIT-Ringvorlesung - Präsentation Unister
IT-Ringvorlesung - Präsentation Unister
 
Responsive Webdesign Process
Responsive Webdesign ProcessResponsive Webdesign Process
Responsive Webdesign Process
 

Offlinefähige Apps für Android entwickeln (Karlsruher Entwicklertag 2014)