Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android開発初心者にありがちなこと

 Android開発初心者にありがちなこと

ginyolithさん発表のスライドです。

andfactory, inc.

October 25, 2018
Tweet

More Decks by andfactory, inc.

Other Decks in Programming

Transcript

  1. ݪҼ public class MainActivity extends Activity { TextView mTextView; @Override

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button1 = findViewById(R.id.button1); mTextView = findViewById(R.id.textView); // ボタン1クリック時 button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new Thread(new Runnable() { @Override public void run() { mTextView.setText("hoge"); } }).start(); } });
  2. ݪҼ public class MainActivity extends Activity { TextView mTextView; @Override

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button1 = findViewById(R.id.button1); mTextView = findViewById(R.id.textView); // ボタン1クリック時 button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new Thread(new Runnable() { @Override public void run() { mTextView.setText("hoge"); } }).start(); } });
  3. νϡʔτϦΞϧͷґଘϥΠϒϥϦ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0'

    implementation 'com.google.android.gms:play-services-maps:15.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' }
  4. νϡʔτϦΞϧͷίʔυ public class MainActivity extends Activity { TextView mTextView; @Override

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button1 = findViewById(R.id.button1); Button button2 = findViewById(R.id.button2); mTextView = findViewById(R.id.textView); // ボタン1クリック時 button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { button1Clicked(); } });
  5. ࣮ࡍͷґଘϥΠϒϥϦ dependencies { // App's dependencies, including test compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"

    compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion" compile "com.android.support:design:$rootProject.supportLibraryVersion" compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion" compile "com.android.support:support-v4:$rootProject.supportLibraryVersion" compile "com.android.support.test.espresso:espresso-idling-resource:$rootProject.espressoVersion" compile "com.google.guava:guava:$rootProject.guavaVersion" compile "android.arch.persistence.room:runtime:$rootProject.roomVersion" annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion" // Dagger dependencies annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.daggerVersion" compile "com.google.dagger:dagger:$rootProject.daggerVersion" compile "com.google.dagger:dagger-android:$rootProject.daggerVersion" compile "com.google.dagger:dagger-android-support:$rootProject.daggerVersion" annotationProcessor "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion" // Dependencies for local unit tests testCompile "junit:junit:$rootProject.ext.junitVersion" testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion" testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion" // Android Testing Support Library's runner and rules androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion" androidTestCompile "com.android.support.test:rules:$rootProject.ext.rulesVersion" androidTestCompile "android.arch.persistence.room:testing:$rootProject.roomVersion" // Dependencies for Android unit tests androidTestCompile "junit:junit:$rootProject.ext.junitVersion" androidTestCompile "org.mockito:mockito-core:$rootProject.ext.mockitoVersion" androidTestCompile "com.google.dexmaker:dexmaker:$rootProject.ext.dexmakerVersion" androidTestCompile "com.google.dexmaker:dexmaker-mockito:$rootProject.ext.dexmakerVersion"
  6. ViewModel…? public class TaskDetailViewModel extends TaskViewModel { @Nullable private TaskDetailNavigator

    mTaskDetailNavigator; public TaskDetailViewModel(Context context, TasksRepository tasksRepository) { super(context, tasksRepository); } public void setNavigator(TaskDetailNavigator taskDetailNavigator) { mTaskDetailNavigator = taskDetailNavigator; } public void onActivityDestroyed() { // Clear references to avoid potential memory leaks. mTaskDetailNavigator = null; }
  7. ֶशͷ༏ઌ౓ 1. ΞʔΩςΫνϟ, databindingͷ࢖͍ํ • MVVM, MVPͳͲɻMVVMͰ͸Databinding͕؊ͱͳΔͷͰ߹ Θͤͯ 2. ػೳ௥Ճʹ΄΅ඞਢͳϥΠϒϥϦ

    • Retrofit, OkHttpͳͲ 3. Ϟμϯͳઃܭ or هड़͕ՄೳͳϥΠϒϥϦ • RxJava, AAC, dagger2, Kotlin etc…
  8. KotlinΛ࢖͏ͱ… // 拡張関数を定義 fun Activity.toast(msg : String) { Toast.makeText(this, msg,

    Toast.LENGTH_SHORT).show() } // Activityを継承するクラスでtoast関数を呼ぶことが可能に fun showToast() { [email protected]("hoge") }
  9. ରࡦ • ϥΠϒϥϦΛ࢖͏ • Robolectric • Android Test ( Android

    Jetpack ) • ຊ౰ʹContextඞཁʁ • ઃܭΛݟ௚͢