SlideShare uma empresa Scribd logo
1 de 95
Baixar para ler offline
Overview of Android
   Infrastructure
             Alexey Buzdin
@AlexeyBuzdin


alex.buzdin@gmail.com


            LArchaon
Everyone needs an app....
We need an app too!
simple CRUD app
Requirement:
Support as many android
   devices as you can
    (including tablets)
4.1–4.2
4.0


                        2.1
3.0                    2.2


2.3

 Google data, March 2013
Ain't that good for a developer
Is there is someone who
      could help us?
nope
Ease our pain
maybe
Layers

 Presentation


Application logic


    Domain
Presentation


Application logic


    Domain
But Whers the problem?
Missing in Android 2.2
●
    ActionBar
●
    Support for tablets
●
    Decent ListView support for server communication
Solution?
Compatability libraries
Android Support library
ActionBarSherlock
etc
Support Library
http://developer.android.com/tools/extras/support-
library.html

                   Fragments
                  Async Stuff
               Experimental stuff
Fragments
Example
ActionBar
ActionBarSherlock




 http://actionbarsherlock.com/
Refreshing list
Pull to Refresh




  https://github.com/chrisbanes/Andro
  id-PullToRefresh
Presentation


Application logic


    Domain
Android Runtime
On Android you develop in Java
  ... but Android does not run Java Bytecode !
DalvikVM
Dalvik Virtual Machine
– Custom VM optimized for mobile devices
– Register-based JVM
– More efficient and compact
– Use memory efficiently
– Dalvik Executable Code (.dex)
   ● 30% fewer instructions

   ● 35% fewer code units

   ● 35% more bytes

– Trace JIT compiler (since 2.2)
Android Runtime
Android Java = Java language + Dalvik + Apache Harmony
Android Java API = Java SE – AWT/Swing + Android API
Sun-Java = Java language + JVM + JDK




                                                         36
App lifecycle
Activity
public class MyActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
    }

}
Activity
public class MyActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
    }

}
Resources
Activity
public class MyActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
    }

}
Context
●
    Context of current state of the
    application/object
Context
●
    Context of current state of the
    application/object
●
    Context is a handle to the system it
    provides services like
    – resolving resources
    – obtaining access to databases and
      preferences
Important
any resource taken from context will
    leave as long as Context does
Context problem
public class MyActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      String appName = getString(R.string.appName);
    }

}
Passing Context
public class MyStringProvider {

    Context context;

    public MyStringProvider(Context context) {
      this.context = context;
    }

    public String getString(){
      return context.getString(R.string.app_name);
    }

}
Passing Context
Context problem
public class MyActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      String appName = getString(R.string.appName);
    }

}
                                                 Presentation


                                               Application logic


                                                    Domain
Injection libraries
  Dependency Injection
●
  RoboGuice
●
  Dagger
RoboGuice

●
    Based on Google Guice
●
    Lightweight
●
    Multifunctional (has resource injection)
RoboGuice
public class MyActivity extends RoboActivity {

    @Inject MyStringProvider stringProvider;

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

        ((TextView) findViewById(R.id.textView))
            .setText(stringProvider.getString());
    }

}
RoboGuice
public class MyStringProvider {

    Context context;

    @Inject
    public MyStringProvider(Context context) {
      this.context = context;
    }

    public String getString(){
      return context.getString(R.string.app_name);
    }
}
Notable fact
Optimezed context injection
public class MyActivity extends RoboActivity {

    int i;

    @Inject MyStringProvider stringProvider;

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

        i = 1;
        ((TextView) findViewById(R.id.textView))
           .setText(stringProvider.getString());
    }

}
RoboGuice
public class MyStringProvider {

    Context context;

    @Inject
    public MyStringProvider(Context context) {
      this.context = context;
    }

    public String getString(){
      return context.getString(R.string.app_name) + ((MyActivity)context).i;
    }
}
Dagger
public class DaggerActivity extends DaggerBaseActivity {

    @Inject DaggerStringProvider stringProvider;

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

        ((TextView) findViewById(R.id.textView))
           .setText(stringProvider.getString());
    }

}
Dagger
public class DaggerBaseActivity extends Activity {

    @Inject
    Bus bus;

    @Override protected void onCreate(Bundle state) {
     super.onCreate(state);

        DaggerApplication.inject(this);
    }

    @Override protected void onResume() {
      super.onResume();
      bus.register(this);
    }

    @Override protected void onPause() {
      super.onPause();
      bus.unregister(this);
    }
}
Dagger
public class DaggerApplication extends Application {

    private static ObjectGraph objectGraph;

    @Override public void onCreate() {
     super.onCreate();

        objectGraph = ObjectGraph.create(new DaggerModule(this));
    }

    public static <T> void inject(T instance) {
      if(objectGraph != null) objectGraph.inject(instance);
    }
}
@Module(
    entryPoints = { DaggerApplication.class, DaggerActivity.class}
)
public class DaggerModule {
  private final Context appContext;

    public DaggerModule(Context appContext) {
      this.appContext = appContext.getApplicationContext();
    }

    @Provides @Singleton Bus provideBus() {
      return new Bus();
    }

    @Provides Context provideContext() {
      return appContext;
    }

}
Summary
    Dagger
●
    More customizable
●
    Easy communicates with other libraries
●
    Requires more code


    RoboGuice
●
    Simpler
●
    Out of Box functionality
Problem with views
Other “Injection” libraries
  Resource and View “Injection”
●
  RoboGuice
●
  ButterKnife
●
  AndroidAnnotations
RoboGuice Views Injection
public class RoboGuiceActivity extends RoboActivity {


    @Inject RoboGuiceStringProvider stringProvider;
    @InjectView(R.id.textView) TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

        textView.setText(stringProvider.getString());
    }

}
Butterknife
public class DaggerActivity extends DaggerBaseActivity {

    @Inject DaggerStringProvider stringProvider;
    @InjectView(R.id.textView) TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Views.inject(this);

        textView.setText(stringProvider.getString());
    }

}
AndroidAnnotations
@EActivity(R.layout.translate) // Sets content view to R.layout.translate
public class TranslateActivity extends Activity {
    @ViewById // Injects R.id.textInput
    EditText textInput;
    @ViewById(R.id.myTextView) // Injects R.id.myTextView
    TextView result;
    @AnimationRes // Injects android.R.anim.fade_in
    Animation fadeIn;
    @Click // When R.id.doTranslate button is clicked
    void doTranslate() {
         translateInBackground(textInput.getText().toString());
    }
    @Background // Executed in a background thread
    void translateInBackground(String textToTranslate) {
         String translatedText = callGoogleTranslate(textToTranslate);
         showResult(translatedText);
    }

    @UiThread // Executed in the ui thread
    void showResult(String translatedText) {
         result.setText(translatedText);
         result.startAnimation(fadeIn);
    }
}
Presentation


Application logic


    Domain
Data Source
Android has built in SQLite
Data Source
... but lacks ORM


Alternatives:
–   GreenDAO
–   ORMLite
ORMLite
@DatabaseTable(tableName = "accounts")
public class Account {
    @DatabaseField(id = true) private String name;


    @DatabaseField(canBeNull = false) private String password;


    Account() {
     // all persisted classes must define a no-arg constructor with at least package
visibility
    }


}
ORMLite
// you get the SQLiteOpenHelper from your Android Activity
ConnectionSource connectionSource = new AndroidConnectionSource(sqliteOpenHelper);


// instantiate the DAO to handle Account with String id
Dao<Account,String> accountDao = BaseDaoImpl.createDao(connectionSource, Account.class);


TableUtils.createTable(connectionSource, Account.class);


                         String name = "Jim Smith";
                         Account account = new Account(name, "_secret");
                         accountDao.create(account)


                         Account account2 = accountDao.queryForId(name);
                         connectionSource.close();
Testing
Testing
●
  DVM or JVM
●
  Automation or Unit Tests
DVM
●
  Requires a separate Test Project
●
  android.test or Robotium
Android.test
public class SimpleActivityTestStandard extends
    ActivityUnitTestCase<SimpleActivity> {
  public SimpleActivityTestStandard() {
    super(SimpleActivity.class);
  }

  public void setUp() throws Exception {
    startActivity(new
Intent(getInstrumentation().getTargetContext(),
        SimpleActivity.class), null, null);
  }

     public void testLayout() {
      SimpleActivity activity = getActivity();
      assertNotNull(activity.findViewById(R.id.button1));
      Button view = (Button) activity
          .findViewById(com.example.test.target.R.id.button1);
      assertEquals("My Button 1", view.getText());
    }
}
 
                       Robotium
    public void testPreferenceIsSaved() throws Exception {
         Solo solo = new Solo(getInstrumentation(), getActivity());
         solo.sendKey(Solo.MENU);
        solo.clickOnText("More");
         solo.clickOnText("Preferences");
         solo.clickOnText("Edit File Extensions");
         assertTrue(solo.searchText("rtf"));
                 
         solo.clickOnText("txt");
         solo.clearEditText(2);
         solo.enterText(2, "robotium");
         solo.clickOnButton("Save");
         solo.goBack();
         solo.clickOnText("Edit File Extensions");

       assertTrue(solo.searchText("application/robotium")
       solo.finishOpenedActivities();
);
               
JVM
public class RoboGuiceActivityTest {

    @Test
    public void shouldHaveISet() throws Exception {
      RoboGuiceActivity activity = new RoboGuiceActivity();
      assertThat(activity.getI(), equalTo(1));
    }
}
JVM
public class RoboGuiceActivityTest {

    @Test
    public void shouldHaveISet() throws Exception {
      RoboGuiceActivity activity = new RoboGuiceActivity();
      assertThat(activity.getI(), equalTo(1));
    }
}
We have Mockito!
lets mock something
   in our Activity ...
Activity source code
Robolectric to the rescue




    Allows you to run
    you android code
         on JVM
Robolectric
@RunWith(RobolectricRoboTestRunner.class)
public class RoboGuiceActivityTest {

    @Test
    public void shouldHaveISet() throws Exception {
      RoboGuiceActivity activity = new RoboGuiceActivity();
      activity.onCreate(null);
      assertThat(activity.getI(), equalTo(1));
    }
}
Robolectric + Mockito
Testing
●
  DVM or JVM
●
  Automation or Unit Tests
●
  Robotium or Robolectric
●
  Or both
Conclusion
More libraries?
More libraries
Solution?
Android Bootstrap
●
    Fragments,Fragment Pager
●
    android-maven-plugin, Dagger
●
    ActionBarSherlock
●
    ViewPagerIndicator
●
    http-request, GSON
●
    Robotium



                 http://www.androidbootstrap.com/
or customs scripts
Build Systems
● Gradle
● Maven




    https://github.com/LArchaon/android
    _mvn_template/
Questions?

Mais conteúdo relacionado

Mais procurados

Google Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG NantesGoogle Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG Nantesmikaelbarbero
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyDavid Gómez García
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadDavid Gómez García
 
Jdk(java) 7 - 6 기타기능
Jdk(java) 7 - 6 기타기능Jdk(java) 7 - 6 기타기능
Jdk(java) 7 - 6 기타기능knight1128
 
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Uehara Junji
 
Demystifying dependency Injection: Dagger and Toothpick
Demystifying dependency Injection: Dagger and ToothpickDemystifying dependency Injection: Dagger and Toothpick
Demystifying dependency Injection: Dagger and ToothpickDanny Preussler
 
Easy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEEasy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEUehara Junji
 
Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1José Paumard
 
Swiss army knife Spring
Swiss army knife SpringSwiss army knife Spring
Swiss army knife SpringMario Fusco
 
Google Guava for cleaner code
Google Guava for cleaner codeGoogle Guava for cleaner code
Google Guava for cleaner codeMite Mitreski
 
Google guava - almost everything you need to know
Google guava - almost everything you need to knowGoogle guava - almost everything you need to know
Google guava - almost everything you need to knowTomasz Dziurko
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsMark Baker
 
Dependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutesDependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutesAntonio Goncalves
 
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Omar Miatello
 

Mais procurados (20)

Google Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG NantesGoogle Guava & EMF @ GTUG Nantes
Google Guava & EMF @ GTUG Nantes
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results Asynchrhonously
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidad
 
Jdk(java) 7 - 6 기타기능
Jdk(java) 7 - 6 기타기능Jdk(java) 7 - 6 기타기능
Jdk(java) 7 - 6 기타기능
 
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
 
Demystifying dependency Injection: Dagger and Toothpick
Demystifying dependency Injection: Dagger and ToothpickDemystifying dependency Injection: Dagger and Toothpick
Demystifying dependency Injection: Dagger and Toothpick
 
Easy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEEasy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVE
 
Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
 
Java lab 2
Java lab 2Java lab 2
Java lab 2
 
Swiss army knife Spring
Swiss army knife SpringSwiss army knife Spring
Swiss army knife Spring
 
Roboguice
RoboguiceRoboguice
Roboguice
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
Google Guava for cleaner code
Google Guava for cleaner codeGoogle Guava for cleaner code
Google Guava for cleaner code
 
Google guava - almost everything you need to know
Google guava - almost everything you need to knowGoogle guava - almost everything you need to know
Google guava - almost everything you need to know
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 
Dependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutesDependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutes
 
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01
 

Destaque (11)

Quantum professional academy
Quantum professional academyQuantum professional academy
Quantum professional academy
 
scan0006
scan0006scan0006
scan0006
 
Crowdsourcing
CrowdsourcingCrowdsourcing
Crowdsourcing
 
ApresMOTOFRETE WEB2015VCliente
ApresMOTOFRETE WEB2015VClienteApresMOTOFRETE WEB2015VCliente
ApresMOTOFRETE WEB2015VCliente
 
PMV Middle East Article and Cover May 2015
PMV Middle East Article and Cover May 2015PMV Middle East Article and Cover May 2015
PMV Middle East Article and Cover May 2015
 
Universidad Técnica Particular de Loja
Universidad Técnica Particular de LojaUniversidad Técnica Particular de Loja
Universidad Técnica Particular de Loja
 
Investor Development & Retention Presentation
Investor Development & Retention PresentationInvestor Development & Retention Presentation
Investor Development & Retention Presentation
 
แบบร่าง
 แบบร่าง แบบร่าง
แบบร่าง
 
Biblioteca Digital Hispánica. Preservar. Difundir. Re-crear
Biblioteca Digital Hispánica. Preservar. Difundir. Re-crearBiblioteca Digital Hispánica. Preservar. Difundir. Re-crear
Biblioteca Digital Hispánica. Preservar. Difundir. Re-crear
 
Presentacion patatas
Presentacion patatasPresentacion patatas
Presentacion patatas
 
Calabazas
CalabazasCalabazas
Calabazas
 

Semelhante a Overview of Android Infrastructure

Modern Android app library stack
Modern Android app library stackModern Android app library stack
Modern Android app library stackTomáš Kypta
 
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalThomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalDroidcon Berlin
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developersPavel Lahoda
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon Berlin
 
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014First Tuesday Bergen
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)Jose Manuel Pereira Garcia
 
Android Bootstrap
Android BootstrapAndroid Bootstrap
Android Bootstrapdonnfelker
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideVisual Engineering
 
Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 BejugEnterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejugrobbiev
 
How to code to code less
How to code to code lessHow to code to code less
How to code to code lessAnton Novikau
 
Taming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeTaming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeMacoscope
 
Architecture components - IT Talk
Architecture components - IT TalkArchitecture components - IT Talk
Architecture components - IT TalkConstantine Mars
 
Architecture Components
Architecture Components Architecture Components
Architecture Components DataArt
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotationjavatwo2011
 

Semelhante a Overview of Android Infrastructure (20)

Modern Android app library stack
Modern Android app library stackModern Android app library stack
Modern Android app library stack
 
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalThomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-final
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
 
Dependency Injection for Android
Dependency Injection for AndroidDependency Injection for Android
Dependency Injection for Android
 
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
Dependency Injection for Android @ Ciklum speakers corner Kiev 29. May 2014
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
Android Bootstrap
Android BootstrapAndroid Bootstrap
Android Bootstrap
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native Side
 
droidparts
droidpartsdroidparts
droidparts
 
Android development
Android developmentAndroid development
Android development
 
Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 BejugEnterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejug
 
How to code to code less
How to code to code lessHow to code to code less
How to code to code less
 
Taming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeTaming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, Macoscope
 
Architecture components - IT Talk
Architecture components - IT TalkArchitecture components - IT Talk
Architecture components - IT Talk
 
Architecture Components
Architecture Components Architecture Components
Architecture Components
 
Arquitecturas de microservicios - Medianet Software
Arquitecturas de microservicios   -  Medianet SoftwareArquitecturas de microservicios   -  Medianet Software
Arquitecturas de microservicios - Medianet Software
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Android best practices
Android best practicesAndroid best practices
Android best practices
 

Mais de C.T.Co

Things They Didn't Teach Me In Academy
Things They Didn't Teach Me In AcademyThings They Didn't Teach Me In Academy
Things They Didn't Teach Me In AcademyC.T.Co
 
Project Management in Information Technologies
Project Management in Information TechnologiesProject Management in Information Technologies
Project Management in Information TechnologiesC.T.Co
 
Mobile vs Desktop
Mobile vs DesktopMobile vs Desktop
Mobile vs DesktopC.T.Co
 
Business Analysis in IT by Ilze Buksha, Latvian
Business Analysis in IT by Ilze Buksha, LatvianBusiness Analysis in IT by Ilze Buksha, Latvian
Business Analysis in IT by Ilze Buksha, LatvianC.T.Co
 
Stratoplan 2013 Brief by C.T.Co
Stratoplan 2013 Brief by C.T.CoStratoplan 2013 Brief by C.T.Co
Stratoplan 2013 Brief by C.T.CoC.T.Co
 
Scrum methodology
Scrum methodology Scrum methodology
Scrum methodology C.T.Co
 
Introduction to Performance Testing Part 1
Introduction to Performance Testing Part 1Introduction to Performance Testing Part 1
Introduction to Performance Testing Part 1C.T.Co
 
Project management in Agile Way
Project management in Agile WayProject management in Agile Way
Project management in Agile WayC.T.Co
 
Data Access using Entity Framework
Data Access using Entity FrameworkData Access using Entity Framework
Data Access using Entity FrameworkC.T.Co
 
Windows phone 7
Windows phone 7Windows phone 7
Windows phone 7C.T.Co
 

Mais de C.T.Co (10)

Things They Didn't Teach Me In Academy
Things They Didn't Teach Me In AcademyThings They Didn't Teach Me In Academy
Things They Didn't Teach Me In Academy
 
Project Management in Information Technologies
Project Management in Information TechnologiesProject Management in Information Technologies
Project Management in Information Technologies
 
Mobile vs Desktop
Mobile vs DesktopMobile vs Desktop
Mobile vs Desktop
 
Business Analysis in IT by Ilze Buksha, Latvian
Business Analysis in IT by Ilze Buksha, LatvianBusiness Analysis in IT by Ilze Buksha, Latvian
Business Analysis in IT by Ilze Buksha, Latvian
 
Stratoplan 2013 Brief by C.T.Co
Stratoplan 2013 Brief by C.T.CoStratoplan 2013 Brief by C.T.Co
Stratoplan 2013 Brief by C.T.Co
 
Scrum methodology
Scrum methodology Scrum methodology
Scrum methodology
 
Introduction to Performance Testing Part 1
Introduction to Performance Testing Part 1Introduction to Performance Testing Part 1
Introduction to Performance Testing Part 1
 
Project management in Agile Way
Project management in Agile WayProject management in Agile Way
Project management in Agile Way
 
Data Access using Entity Framework
Data Access using Entity FrameworkData Access using Entity Framework
Data Access using Entity Framework
 
Windows phone 7
Windows phone 7Windows phone 7
Windows phone 7
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Último (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Overview of Android Infrastructure

  • 1. Overview of Android Infrastructure Alexey Buzdin
  • 4. We need an app too!
  • 6.
  • 7. Requirement: Support as many android devices as you can (including tablets)
  • 8. 4.1–4.2 4.0 2.1 3.0 2.2 2.3 Google data, March 2013
  • 9.
  • 10. Ain't that good for a developer
  • 11.
  • 12.
  • 13.
  • 14. Is there is someone who could help us?
  • 15. nope
  • 17. maybe
  • 18.
  • 19.
  • 22. But Whers the problem?
  • 23. Missing in Android 2.2 ● ActionBar ● Support for tablets ● Decent ListView support for server communication
  • 25. Compatability libraries Android Support library ActionBarSherlock etc
  • 32. Pull to Refresh https://github.com/chrisbanes/Andro id-PullToRefresh
  • 34. Android Runtime On Android you develop in Java ... but Android does not run Java Bytecode !
  • 35. DalvikVM Dalvik Virtual Machine – Custom VM optimized for mobile devices – Register-based JVM – More efficient and compact – Use memory efficiently – Dalvik Executable Code (.dex) ● 30% fewer instructions ● 35% fewer code units ● 35% more bytes – Trace JIT compiler (since 2.2)
  • 36. Android Runtime Android Java = Java language + Dalvik + Apache Harmony Android Java API = Java SE – AWT/Swing + Android API Sun-Java = Java language + JVM + JDK 36
  • 38. Activity public class MyActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
  • 39.
  • 40. Activity public class MyActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
  • 42. Activity public class MyActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
  • 43. Context ● Context of current state of the application/object
  • 44. Context ● Context of current state of the application/object ● Context is a handle to the system it provides services like – resolving resources – obtaining access to databases and preferences
  • 45. Important any resource taken from context will leave as long as Context does
  • 46. Context problem public class MyActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String appName = getString(R.string.appName); } }
  • 47. Passing Context public class MyStringProvider { Context context; public MyStringProvider(Context context) { this.context = context; } public String getString(){ return context.getString(R.string.app_name); } }
  • 49. Context problem public class MyActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String appName = getString(R.string.appName); } } Presentation Application logic Domain
  • 50. Injection libraries Dependency Injection ● RoboGuice ● Dagger
  • 51. RoboGuice ● Based on Google Guice ● Lightweight ● Multifunctional (has resource injection)
  • 52. RoboGuice public class MyActivity extends RoboActivity { @Inject MyStringProvider stringProvider; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ((TextView) findViewById(R.id.textView)) .setText(stringProvider.getString()); } }
  • 53. RoboGuice public class MyStringProvider { Context context; @Inject public MyStringProvider(Context context) { this.context = context; } public String getString(){ return context.getString(R.string.app_name); } }
  • 55. Optimezed context injection public class MyActivity extends RoboActivity { int i; @Inject MyStringProvider stringProvider; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); i = 1; ((TextView) findViewById(R.id.textView)) .setText(stringProvider.getString()); } }
  • 56. RoboGuice public class MyStringProvider { Context context; @Inject public MyStringProvider(Context context) { this.context = context; } public String getString(){ return context.getString(R.string.app_name) + ((MyActivity)context).i; } }
  • 57. Dagger public class DaggerActivity extends DaggerBaseActivity { @Inject DaggerStringProvider stringProvider; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ((TextView) findViewById(R.id.textView)) .setText(stringProvider.getString()); } }
  • 58. Dagger public class DaggerBaseActivity extends Activity { @Inject Bus bus; @Override protected void onCreate(Bundle state) { super.onCreate(state); DaggerApplication.inject(this); } @Override protected void onResume() { super.onResume(); bus.register(this); } @Override protected void onPause() { super.onPause(); bus.unregister(this); } }
  • 59. Dagger public class DaggerApplication extends Application { private static ObjectGraph objectGraph; @Override public void onCreate() { super.onCreate(); objectGraph = ObjectGraph.create(new DaggerModule(this)); } public static <T> void inject(T instance) { if(objectGraph != null) objectGraph.inject(instance); } }
  • 60. @Module( entryPoints = { DaggerApplication.class, DaggerActivity.class} ) public class DaggerModule { private final Context appContext; public DaggerModule(Context appContext) { this.appContext = appContext.getApplicationContext(); } @Provides @Singleton Bus provideBus() { return new Bus(); } @Provides Context provideContext() { return appContext; } }
  • 61. Summary Dagger ● More customizable ● Easy communicates with other libraries ● Requires more code RoboGuice ● Simpler ● Out of Box functionality
  • 63.
  • 64.
  • 65. Other “Injection” libraries Resource and View “Injection” ● RoboGuice ● ButterKnife ● AndroidAnnotations
  • 66. RoboGuice Views Injection public class RoboGuiceActivity extends RoboActivity { @Inject RoboGuiceStringProvider stringProvider; @InjectView(R.id.textView) TextView textView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView.setText(stringProvider.getString()); } }
  • 67. Butterknife public class DaggerActivity extends DaggerBaseActivity { @Inject DaggerStringProvider stringProvider; @InjectView(R.id.textView) TextView textView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Views.inject(this); textView.setText(stringProvider.getString()); } }
  • 68. AndroidAnnotations @EActivity(R.layout.translate) // Sets content view to R.layout.translate public class TranslateActivity extends Activity { @ViewById // Injects R.id.textInput EditText textInput; @ViewById(R.id.myTextView) // Injects R.id.myTextView TextView result; @AnimationRes // Injects android.R.anim.fade_in Animation fadeIn; @Click // When R.id.doTranslate button is clicked void doTranslate() { translateInBackground(textInput.getText().toString()); } @Background // Executed in a background thread void translateInBackground(String textToTranslate) { String translatedText = callGoogleTranslate(textToTranslate); showResult(translatedText); } @UiThread // Executed in the ui thread void showResult(String translatedText) { result.setText(translatedText); result.startAnimation(fadeIn); } }
  • 70. Data Source Android has built in SQLite
  • 71. Data Source ... but lacks ORM Alternatives: – GreenDAO – ORMLite
  • 72. ORMLite @DatabaseTable(tableName = "accounts") public class Account { @DatabaseField(id = true) private String name; @DatabaseField(canBeNull = false) private String password; Account() { // all persisted classes must define a no-arg constructor with at least package visibility } }
  • 73. ORMLite // you get the SQLiteOpenHelper from your Android Activity ConnectionSource connectionSource = new AndroidConnectionSource(sqliteOpenHelper); // instantiate the DAO to handle Account with String id Dao<Account,String> accountDao = BaseDaoImpl.createDao(connectionSource, Account.class); TableUtils.createTable(connectionSource, Account.class); String name = "Jim Smith"; Account account = new Account(name, "_secret"); accountDao.create(account) Account account2 = accountDao.queryForId(name); connectionSource.close();
  • 75. Testing ● DVM or JVM ● Automation or Unit Tests
  • 76. DVM ● Requires a separate Test Project ● android.test or Robotium
  • 77. Android.test public class SimpleActivityTestStandard extends ActivityUnitTestCase<SimpleActivity> { public SimpleActivityTestStandard() { super(SimpleActivity.class); } public void setUp() throws Exception { startActivity(new Intent(getInstrumentation().getTargetContext(), SimpleActivity.class), null, null); } public void testLayout() { SimpleActivity activity = getActivity(); assertNotNull(activity.findViewById(R.id.button1)); Button view = (Button) activity .findViewById(com.example.test.target.R.id.button1); assertEquals("My Button 1", view.getText()); } }
  • 78.   Robotium   public void testPreferenceIsSaved() throws Exception {   Solo solo = new Solo(getInstrumentation(), getActivity());        solo.sendKey(Solo.MENU);       solo.clickOnText("More");        solo.clickOnText("Preferences");        solo.clickOnText("Edit File Extensions");        assertTrue(solo.searchText("rtf"));                        solo.clickOnText("txt");        solo.clearEditText(2);        solo.enterText(2, "robotium");        solo.clickOnButton("Save");        solo.goBack();        solo.clickOnText("Edit File Extensions");        assertTrue(solo.searchText("application/robotium") solo.finishOpenedActivities(); );                
  • 79. JVM public class RoboGuiceActivityTest { @Test public void shouldHaveISet() throws Exception { RoboGuiceActivity activity = new RoboGuiceActivity(); assertThat(activity.getI(), equalTo(1)); } }
  • 80. JVM public class RoboGuiceActivityTest { @Test public void shouldHaveISet() throws Exception { RoboGuiceActivity activity = new RoboGuiceActivity(); assertThat(activity.getI(), equalTo(1)); } }
  • 81.
  • 82. We have Mockito! lets mock something in our Activity ...
  • 84. Robolectric to the rescue Allows you to run you android code on JVM
  • 85. Robolectric @RunWith(RobolectricRoboTestRunner.class) public class RoboGuiceActivityTest { @Test public void shouldHaveISet() throws Exception { RoboGuiceActivity activity = new RoboGuiceActivity(); activity.onCreate(null); assertThat(activity.getI(), equalTo(1)); } }
  • 87. Testing ● DVM or JVM ● Automation or Unit Tests ● Robotium or Robolectric ● Or both
  • 92. Android Bootstrap ● Fragments,Fragment Pager ● android-maven-plugin, Dagger ● ActionBarSherlock ● ViewPagerIndicator ● http-request, GSON ● Robotium http://www.androidbootstrap.com/
  • 94. Build Systems ● Gradle ● Maven https://github.com/LArchaon/android _mvn_template/