SlideShare a Scribd company logo
ANDROID




Does not Suck anymore!
Andy Rubin
No plans to leave Google. Oh, and just for
meme completeness -- there are over 900,000
android devices activated each day :-)
Android evolves
Android Design Patterns




http://developer.android.com/design/index.html
No More Menu Button
New Buttons
Notifications
Navigation
ActionBar
Action Bar Selection
MultiPane
Dialogs
Android is not ios
IOS Design


It was cool 2 years ago
Android is not ios
Fragmentation
Fragmentation
Fragmentation
Shut up and Show me Code Bitch!
Android Support Jar
●   V4                             ●   V13
●   Fragment                       ●   FragmentCompat

●   FragmentManager                ●   FragmentPagerAdapter

●   FragmentTransaction            ●   FragmentStatePagerAdapter

●   ListFragment

●   DialogFragment

●   LoaderManager

●   Loader

●   AsyncTaskLoader

●   CursorLoader
Support Jar



Just change the import and use latest api's

                It rocks!!!
Fragment
●   Tablet and phone code comes together

●   One ring to rule them all!!!
Fragment
Define in XML

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

  android:layout_width="match_parent" android:layout_height="match_parent">

  <fragment class="com.example.android.apis.app.FragmentLayout$TitlesFragment"

       android:id="@+id/titles"

       android:layout_width="match_parent" android:layout_height="match_parent" />

</FrameLayout>

Set Content in code

setContentView(R.layout.fragment_layout);

It works just like activity

public static class TitlesFragment extends ListFragment {
Create Fragment
DetailsFragment f = new DetailsFragment();


    // Supply index input as an argument.
    Bundle args = new Bundle();
    args.putInt("index", index);
    f.setArguments(args);
Fire the fragment
// Instantiate a new fragment.
 Fragment newFragment = CountingFragment.newInstance(mStackLevel);


 // Add the fragment to the activity, pushing this transaction
 // on to the back stack.
 FragmentTransaction ft = getFragmentManager().beginTransaction();
 ft.replace(R.id.simple_fragment, newFragment);
 ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
 ft.addToBackStack(null);
 ft.commit();
Get the parameters
@Override public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);


      Bundle args = getArguments();
      if (args != null) {
          mLabel = args.getCharSequence("label", mLabel);
      }
  }
Use XML



As much as you can
Inflate Views
●   Design using XML


●   And @java
View v = inflater.inflate(R.layout.hello_world, container, false);
 View tv = v.findViewById(R.id.text);
DialogFragment
Better Back button support

public static class MyDialogFragment extends DialogFragment {
Other Fragments
●   ListFragment
●   PreferenceFragment
Loaders
●   Loader Callback Methods
onCreateLoader()
OnLoadFinished()
onLoaderReset()
Great Man



●   Jack Wharton
https://github.com/JakeWharton
Libraries
●   ActionBarSherlock
●   ActivityCompat2
●   NotificationCompat2
●   NineOldAndroids
●   SwipeToDismissNOA
●   Android-ViewPagerIndicator
ActionBarSherlock

●   At last you can use great ActionBar
●   Just use
getSupportActionBar()
●   Instead of
getActionBar()
NineOldAndroids
 ●   ObjectAnimator.ofFloat(myObject, "translationY", -myObject.getHeight()).start();


AnimatorSet set = new AnimatorSet();
set.playTogether(
     ObjectAnimator.ofFloat(myView, "rotationX", 0, 360),
     ObjectAnimator.ofFloat(myView, "rotationY", 0, 180),
     ObjectAnimator.ofFloat(myView, "rotation", 0, -90),
     ObjectAnimator.ofFloat(myView, "translationX", 0, 90),
     ObjectAnimator.ofFloat(myView, "translationY", 0, 90),
     ObjectAnimator.ofFloat(myView, "scaleX", 1, 1.5f),
     ObjectAnimator.ofFloat(myView, "scaleY", 1, 0.5f),
     ObjectAnimator.ofFloat(myView, "alpha", 1, 0.25f, 1)
);
set.setDuration(5 * 1000).start();
ViewPagerIndicator
XML
<com.viewpagerindicator.TitlePageIndicator
  android:id="@+id/titles"
  android:layout_height="wrap_content"
  android:layout_width="fill_parent" />
ViewPagerIndicator
@Java
//Set the pager with an adapter
ViewPager pager = (ViewPager)findViewById(R.id.pager);
pager.setAdapter(new TestAdapter(getSupportFragmentManager()));


//Bind the title indicator to the adapter
TitlePageIndicator titleIndicator = (TitlePageIndicator)findViewById(R.id.titles);
titleIndicator.setViewPager(pager);
titleIndicator.setOnPageChangeListener(mPageChangeListener);
Activity LifeCycle
Activity LifeCycle
public class Activity extends ApplicationContext {
    protected void onCreate(Bundle savedInstanceState);


    protected void onStart();


    protected void onRestart();


    protected void onResume();


    protected void onPause();


    protected void onStop();


    protected void onDestroy();
}
Send Parameter
●   Bundle
Send
Intent data = new Intent("my.action");
data.putExtra("point", point);
data.putExtra("noqs", noqs);
Get
Bundle b = getIntent().getExtras();
noqs = b.getInt("noqs");
point = b.getInt("point");
Send Parameter
Parcelable
protected static class Foo implements Parcelable {
  public static final Parcelable.Creator<Foo> CREATOR = new Parcelable.Creator<Foo>() {
       public Foo createFromParcel(Parcel source) {
           final Foo f = new Foo();
           f.str = (String) source.readValue(Foo.class.getClassLoader());
           return f;
       }


       public Foo[] newArray(int size) {
           throw new UnsupportedOperationException();
       }


  };
Support multiple Screens
res/layout/main.xml: single-pane layout
res/layout-large: multi-pane layout
res/layout-sw600dp: multi-pane layout
res/values/layouts.xml
res/values-sw600dp-land/layouts.xml
res/values-sw600dp-port/layouts.xml
res/values-large-land/layouts.xml
res/values-large-port/layouts.xml
Do not use px
 ●   Use dp and sp
<Button android:layout_width="wrap_content"
  android:layout_height="wrap_content"

  android:text="@string/clickme"
  android:layout_marginTop="20dp" />

<TextView android:layout_width="match_parent"
  android:layout_height="wrap_content"

  android:textSize="20sp" />
Bitmap Sizes
●   xhdpi: 2.0
●   hdpi: 1.5
●   mdpi: 1.0 (baseline)
●   ldpi: 0.75
Bitmap Resources
MyProject/
 res/
  drawable-xhdpi/
        awesomeimage.png
  drawable-hdpi/
        awesomeimage.png
  drawable-mdpi/
        awesomeimage.png
  drawable-ldpi/
        awesomeimage.png
UI Thread
    ●   WTF is ANR
Won't Work
handler=new Handler();
Runnable r=new Runnable()
{
        public void run()
        {
            tv.append("Hello World");
        }
};
handler.postDelayed(r, 1000);
Android Threads
@Override
publicvoid onClick(View v){
    my_button.setBackgroundResource(R.drawable.icon);
    // SLEEP 2 SECONDS HERE ...
    Handler handler =newHandler();
    handler.postDelayed(newRunnable(){
       publicvoid run(){
           my_button.setBackgroundResource(R.drawable.defaultcard);
       }
    },2000);
}
Android Threads
@Override
publicvoid onClick(View v){
    my_button.setBackgroundResource(R.drawable.icon);
    // SLEEP 2 SECONDS HERE ...
    Handler handler =newHandler();
    handler.postDelayed(newRunnable(){
       publicvoid run(){
           my_button.setBackgroundResource(R.drawable.defaultcard);
       }
    },2000);
}
AsyncTask
private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
    protected Long doInBackground(URL... urls) {
        int count = urls.length;
        long totalSize = 0;
        for (int i = 0; i < count; i++) {
            totalSize += Downloader.downloadFile(urls[i]);
            publishProgress((int) ((i / (float) count) * 100));
            // Escape early if cancel() is called
            if (isCancelled()) break;
        }
        return totalSize;
    }


    protected void onProgressUpdate(Integer... progress) {
        setProgressPercent(progress[0]);
    }


    protected void onPostExecute(Long result) {
        showDialog("Downloaded " + result + " bytes");
    }
}
new DownloadFilesTask().execute(url1, url2, url3);
new DownloadFilesTask().execute(url1, url2, url3);
HTTP Libraries
You can use Apache commons
Or I found these libraries well
http://loopj.com/android-async-http/
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://www.google.com", new AsyncHttpResponseHandler() {
      @Override
      public void onSuccess(String response) {
          System.out.println(response);
      }
});
This works as well
http://code.google.com/p/android-query/
Push Notifications
 ●     Google Cloud Messaging
http://developer.android.com/guide/google/gcm/index.html
@manifest.xml
<permission android:name="my_app_package.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="my_app_package.permission.C2D_MESSAGE" />
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
...
  <intent-filter>
      <action android:name="com.google.android.c2dm.intent.RECEIVE" />
      <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
      <category android:name="my_app_package" />
  </intent-filter>
</receiver>
Push Notifications
@java
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);

final String regId = GCMRegistrar.getRegistrationId(this);


Get regId and fire it from server
You should use this library, all other are deprecated
Dependency Injection
 ●   Roboguice
http://code.google.com/p/roboguice/

 ●   Guava
http://code.google.com/p/guava-libraries/
WTF is DI
    ●       Before DI                                       ●   After DI
class AndroidWay extends Activity {                         class RoboWay extends RoboActivity {
                                                              @InjectView(R.id.name)            TextView
        TextView name;
                                                            name;
        public void onCreate(Bundle savedInstanceState) {     public void onCreate(Bundle
            super.onCreate(savedInstanceState);
                                                            savedInstanceState) {
                                                                    super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
                                                                    setContentView(R.layout.main);
            name    = (TextView) findViewById(R.id.name);           name.setText( "Hello, " + myName );
        }                                                       }
}                                                           }
Image Caching
 ●   Google I/O 2012 app has a great image
     caching library
http://code.google.com/p/iosched/
Open Source apps
 ●   Google I/O 2012
http://code.google.com/p/iosched/

 ●   Github app
https://github.com/github/android
ListView
Most important widget
Fast ListView Tips
 ●   Inflate once
 ●   ViewHolder
 ●   Use Tag
 ●   Don't write a heavy code like network operation in getView
     method
http://yekmer.posterous.com/fast-listview-scrolling-in-android

More Related Content

What's hot

The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]
Nilhcem
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploy
Simon Su
 
Android Wear Essentials
Android Wear EssentialsAndroid Wear Essentials
Android Wear Essentials
Nilhcem
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
 
Learning Dtrace
Learning DtraceLearning Dtrace
Learning Dtrace
JeongHun Byeon
 
droidQuery: The Android port of jQuery
droidQuery: The Android port of jQuerydroidQuery: The Android port of jQuery
droidQuery: The Android port of jQuery
PhDBrown
 
The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]
Nilhcem
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2
Chul Ju Hong
 
Security: Odoo Code Hardening
Security: Odoo Code HardeningSecurity: Odoo Code Hardening
Security: Odoo Code Hardening
Odoo
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2
ang0123dev
 
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"
IT Event
 
WebXR if X = how?
WebXR if X = how?WebXR if X = how?
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
Android code puzzlers + tips & tricks
Android code puzzlers + tips & tricksAndroid code puzzlers + tips & tricks
Android code puzzlers + tips & tricks
NLJUG
 
IPC 2015 ZF2rapid
IPC 2015 ZF2rapidIPC 2015 ZF2rapid
IPC 2015 ZF2rapid
Ralf Eggert
 
Matching Game In Java
Matching Game In JavaMatching Game In Java
Matching Game In Java
cmkandemir
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
zfconfua
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
Bastian Feder
 
Gdg san diego android 11 meetups what's new in android - ui and dev tools
Gdg san diego android 11 meetups  what's new in android  - ui and dev toolsGdg san diego android 11 meetups  what's new in android  - ui and dev tools
Gdg san diego android 11 meetups what's new in android - ui and dev tools
Svetlin Stanchev
 
"Auth for React.js APP", Nikita Galkin
"Auth for React.js APP", Nikita Galkin"Auth for React.js APP", Nikita Galkin
"Auth for React.js APP", Nikita Galkin
Fwdays
 

What's hot (20)

The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploy
 
Android Wear Essentials
Android Wear EssentialsAndroid Wear Essentials
Android Wear Essentials
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
Learning Dtrace
Learning DtraceLearning Dtrace
Learning Dtrace
 
droidQuery: The Android port of jQuery
droidQuery: The Android port of jQuerydroidQuery: The Android port of jQuery
droidQuery: The Android port of jQuery
 
The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]The 2016 Android Developer Toolbox [NANTES]
The 2016 Android Developer Toolbox [NANTES]
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2
 
Security: Odoo Code Hardening
Security: Odoo Code HardeningSecurity: Odoo Code Hardening
Security: Odoo Code Hardening
 
안드로이드 세미나 2
안드로이드 세미나 2안드로이드 세미나 2
안드로이드 세미나 2
 
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"
 
WebXR if X = how?
WebXR if X = how?WebXR if X = how?
WebXR if X = how?
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 
Android code puzzlers + tips & tricks
Android code puzzlers + tips & tricksAndroid code puzzlers + tips & tricks
Android code puzzlers + tips & tricks
 
IPC 2015 ZF2rapid
IPC 2015 ZF2rapidIPC 2015 ZF2rapid
IPC 2015 ZF2rapid
 
Matching Game In Java
Matching Game In JavaMatching Game In Java
Matching Game In Java
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
Gdg san diego android 11 meetups what's new in android - ui and dev tools
Gdg san diego android 11 meetups  what's new in android  - ui and dev toolsGdg san diego android 11 meetups  what's new in android  - ui and dev tools
Gdg san diego android 11 meetups what's new in android - ui and dev tools
 
"Auth for React.js APP", Nikita Galkin
"Auth for React.js APP", Nikita Galkin"Auth for React.js APP", Nikita Galkin
"Auth for React.js APP", Nikita Galkin
 

Similar to Android Best Practices

Android 3
Android 3Android 3
Android 3
Robert Cooper
 
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
Pavel Lahoda
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
Droidcon Berlin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
C.T.Co
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in Android
Robert Cooper
 
Mini curso Android
Mini curso AndroidMini curso Android
Mini curso Android
Mario Jorge Pereira
 
Androidaop 170105090257
Androidaop 170105090257Androidaop 170105090257
Androidaop 170105090257
newegg
 
Android workshop
Android workshopAndroid workshop
Android workshop
Michael Galpin
 
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15
Murat Yener
 
Fragments anyone
Fragments anyone Fragments anyone
Fragments anyone
Yossi Elkrief
 
Design Patterns for Tablets and Smartphones
Design Patterns for Tablets and SmartphonesDesign Patterns for Tablets and Smartphones
Design Patterns for Tablets and Smartphones
Michael Galpin
 
Introduction to angular js
Introduction to angular jsIntroduction to angular js
Introduction to angular js
Marco Vito Moscaritolo
 
Android best practices
Android best practicesAndroid best practices
Android best practices
Jose Manuel Ortega Candel
 
Android training in mumbai
Android training in mumbaiAndroid training in mumbai
Android training in mumbai
CIBIL
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver
yangdj
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegap
yangdj
 
Android For All The Things
Android For All The ThingsAndroid For All The Things
Android For All The Things
Paul Trebilcox-Ruiz
 
Android - Anatomy of android elements & layouts
Android - Anatomy of android elements & layoutsAndroid - Anatomy of android elements & layouts
Android - Anatomy of android elements & layouts
Vibrant Technologies & Computers
 
Android development
Android developmentAndroid development
Android development
Gregoire BARRET
 

Similar to Android Best Practices (20)

Android 3
Android 3Android 3
Android 3
 
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
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in Android
 
Mini curso Android
Mini curso AndroidMini curso Android
Mini curso Android
 
Androidaop 170105090257
Androidaop 170105090257Androidaop 170105090257
Androidaop 170105090257
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15
 
Fragments anyone
Fragments anyone Fragments anyone
Fragments anyone
 
Design Patterns for Tablets and Smartphones
Design Patterns for Tablets and SmartphonesDesign Patterns for Tablets and Smartphones
Design Patterns for Tablets and Smartphones
 
Introduction to angular js
Introduction to angular jsIntroduction to angular js
Introduction to angular js
 
Android best practices
Android best practicesAndroid best practices
Android best practices
 
Android training in mumbai
Android training in mumbaiAndroid training in mumbai
Android training in mumbai
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegap
 
Android For All The Things
Android For All The ThingsAndroid For All The Things
Android For All The Things
 
Android - Anatomy of android elements & layouts
Android - Anatomy of android elements & layoutsAndroid - Anatomy of android elements & layouts
Android - Anatomy of android elements & layouts
 
Android development
Android developmentAndroid development
Android development
 

Recently uploaded

Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 

Recently uploaded (20)

Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 

Android Best Practices

  • 2. Andy Rubin No plans to leave Google. Oh, and just for meme completeness -- there are over 900,000 android devices activated each day :-)
  • 5. No More Menu Button
  • 14. IOS Design It was cool 2 years ago
  • 19. Shut up and Show me Code Bitch!
  • 20. Android Support Jar ● V4 ● V13 ● Fragment ● FragmentCompat ● FragmentManager ● FragmentPagerAdapter ● FragmentTransaction ● FragmentStatePagerAdapter ● ListFragment ● DialogFragment ● LoaderManager ● Loader ● AsyncTaskLoader ● CursorLoader
  • 21. Support Jar Just change the import and use latest api's It rocks!!!
  • 22. Fragment ● Tablet and phone code comes together ● One ring to rule them all!!!
  • 23. Fragment Define in XML <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment class="com.example.android.apis.app.FragmentLayout$TitlesFragment" android:id="@+id/titles" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout> Set Content in code setContentView(R.layout.fragment_layout); It works just like activity public static class TitlesFragment extends ListFragment {
  • 24. Create Fragment DetailsFragment f = new DetailsFragment(); // Supply index input as an argument. Bundle args = new Bundle(); args.putInt("index", index); f.setArguments(args);
  • 25. Fire the fragment // Instantiate a new fragment. Fragment newFragment = CountingFragment.newInstance(mStackLevel); // Add the fragment to the activity, pushing this transaction // on to the back stack. FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.simple_fragment, newFragment); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.addToBackStack(null); ft.commit();
  • 26. Get the parameters @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args = getArguments(); if (args != null) { mLabel = args.getCharSequence("label", mLabel); } }
  • 27. Use XML As much as you can
  • 28. Inflate Views ● Design using XML ● And @java View v = inflater.inflate(R.layout.hello_world, container, false); View tv = v.findViewById(R.id.text);
  • 29. DialogFragment Better Back button support public static class MyDialogFragment extends DialogFragment {
  • 30. Other Fragments ● ListFragment ● PreferenceFragment
  • 31. Loaders ● Loader Callback Methods onCreateLoader() OnLoadFinished() onLoaderReset()
  • 32. Great Man ● Jack Wharton https://github.com/JakeWharton
  • 33. Libraries ● ActionBarSherlock ● ActivityCompat2 ● NotificationCompat2 ● NineOldAndroids ● SwipeToDismissNOA ● Android-ViewPagerIndicator
  • 34. ActionBarSherlock ● At last you can use great ActionBar ● Just use getSupportActionBar() ● Instead of getActionBar()
  • 35. NineOldAndroids ● ObjectAnimator.ofFloat(myObject, "translationY", -myObject.getHeight()).start(); AnimatorSet set = new AnimatorSet(); set.playTogether( ObjectAnimator.ofFloat(myView, "rotationX", 0, 360), ObjectAnimator.ofFloat(myView, "rotationY", 0, 180), ObjectAnimator.ofFloat(myView, "rotation", 0, -90), ObjectAnimator.ofFloat(myView, "translationX", 0, 90), ObjectAnimator.ofFloat(myView, "translationY", 0, 90), ObjectAnimator.ofFloat(myView, "scaleX", 1, 1.5f), ObjectAnimator.ofFloat(myView, "scaleY", 1, 0.5f), ObjectAnimator.ofFloat(myView, "alpha", 1, 0.25f, 1) ); set.setDuration(5 * 1000).start();
  • 36. ViewPagerIndicator XML <com.viewpagerindicator.TitlePageIndicator android:id="@+id/titles" android:layout_height="wrap_content" android:layout_width="fill_parent" />
  • 37. ViewPagerIndicator @Java //Set the pager with an adapter ViewPager pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(new TestAdapter(getSupportFragmentManager())); //Bind the title indicator to the adapter TitlePageIndicator titleIndicator = (TitlePageIndicator)findViewById(R.id.titles); titleIndicator.setViewPager(pager); titleIndicator.setOnPageChangeListener(mPageChangeListener);
  • 39. Activity LifeCycle public class Activity extends ApplicationContext { protected void onCreate(Bundle savedInstanceState); protected void onStart(); protected void onRestart(); protected void onResume(); protected void onPause(); protected void onStop(); protected void onDestroy(); }
  • 40.
  • 41. Send Parameter ● Bundle Send Intent data = new Intent("my.action"); data.putExtra("point", point); data.putExtra("noqs", noqs); Get Bundle b = getIntent().getExtras(); noqs = b.getInt("noqs"); point = b.getInt("point");
  • 42. Send Parameter Parcelable protected static class Foo implements Parcelable { public static final Parcelable.Creator<Foo> CREATOR = new Parcelable.Creator<Foo>() { public Foo createFromParcel(Parcel source) { final Foo f = new Foo(); f.str = (String) source.readValue(Foo.class.getClassLoader()); return f; } public Foo[] newArray(int size) { throw new UnsupportedOperationException(); } };
  • 43. Support multiple Screens res/layout/main.xml: single-pane layout res/layout-large: multi-pane layout res/layout-sw600dp: multi-pane layout res/values/layouts.xml res/values-sw600dp-land/layouts.xml res/values-sw600dp-port/layouts.xml res/values-large-land/layouts.xml res/values-large-port/layouts.xml
  • 44. Do not use px ● Use dp and sp <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/clickme" android:layout_marginTop="20dp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20sp" />
  • 45. Bitmap Sizes ● xhdpi: 2.0 ● hdpi: 1.5 ● mdpi: 1.0 (baseline) ● ldpi: 0.75
  • 46. Bitmap Resources MyProject/ res/ drawable-xhdpi/ awesomeimage.png drawable-hdpi/ awesomeimage.png drawable-mdpi/ awesomeimage.png drawable-ldpi/ awesomeimage.png
  • 47. UI Thread ● WTF is ANR Won't Work handler=new Handler(); Runnable r=new Runnable() { public void run() { tv.append("Hello World"); } }; handler.postDelayed(r, 1000);
  • 48. Android Threads @Override publicvoid onClick(View v){ my_button.setBackgroundResource(R.drawable.icon); // SLEEP 2 SECONDS HERE ... Handler handler =newHandler(); handler.postDelayed(newRunnable(){ publicvoid run(){ my_button.setBackgroundResource(R.drawable.defaultcard); } },2000); }
  • 49. Android Threads @Override publicvoid onClick(View v){ my_button.setBackgroundResource(R.drawable.icon); // SLEEP 2 SECONDS HERE ... Handler handler =newHandler(); handler.postDelayed(newRunnable(){ publicvoid run(){ my_button.setBackgroundResource(R.drawable.defaultcard); } },2000); }
  • 50. AsyncTask private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> { protected Long doInBackground(URL... urls) { int count = urls.length; long totalSize = 0; for (int i = 0; i < count; i++) { totalSize += Downloader.downloadFile(urls[i]); publishProgress((int) ((i / (float) count) * 100)); // Escape early if cancel() is called if (isCancelled()) break; } return totalSize; } protected void onProgressUpdate(Integer... progress) { setProgressPercent(progress[0]); } protected void onPostExecute(Long result) { showDialog("Downloaded " + result + " bytes"); } } new DownloadFilesTask().execute(url1, url2, url3); new DownloadFilesTask().execute(url1, url2, url3);
  • 51. HTTP Libraries You can use Apache commons Or I found these libraries well http://loopj.com/android-async-http/ AsyncHttpClient client = new AsyncHttpClient(); client.get("http://www.google.com", new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { System.out.println(response); } }); This works as well http://code.google.com/p/android-query/
  • 52. Push Notifications ● Google Cloud Messaging http://developer.android.com/guide/google/gcm/index.html @manifest.xml <permission android:name="my_app_package.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="my_app_package.permission.C2D_MESSAGE" /> <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > ... <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="my_app_package" /> </intent-filter> </receiver>
  • 53. Push Notifications @java GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); final String regId = GCMRegistrar.getRegistrationId(this); Get regId and fire it from server You should use this library, all other are deprecated
  • 54. Dependency Injection ● Roboguice http://code.google.com/p/roboguice/ ● Guava http://code.google.com/p/guava-libraries/
  • 55. WTF is DI ● Before DI ● After DI class AndroidWay extends Activity { class RoboWay extends RoboActivity { @InjectView(R.id.name) TextView TextView name; name; public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle super.onCreate(savedInstanceState); savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setContentView(R.layout.main); name = (TextView) findViewById(R.id.name); name.setText( "Hello, " + myName ); } } } }
  • 56. Image Caching ● Google I/O 2012 app has a great image caching library http://code.google.com/p/iosched/
  • 57. Open Source apps ● Google I/O 2012 http://code.google.com/p/iosched/ ● Github app https://github.com/github/android
  • 58. ListView Most important widget Fast ListView Tips ● Inflate once ● ViewHolder ● Use Tag ● Don't write a heavy code like network operation in getView method http://yekmer.posterous.com/fast-listview-scrolling-in-android