26
Developing Android Apps FOR FUN! CLAIRE HYUNJUNG LEE

Developing Android Apps

Embed Size (px)

Citation preview

Page 1: Developing Android Apps

Developing Android AppsFOR FUN!CLAIRE HYUNJUNG LEE

Page 2: Developing Android Apps

Contens

Getting Started

Activity and Fragment

Start Your Own Project

Bug and Trouble Shooting

Page 3: Developing Android Apps

Getting Started

Installing Android Studio and SDKhttps://developer.android.com/sdk/index.html

Page 5: Developing Android Apps

Getting Started

Create New Project Let’s start your own project

Page 7: Developing Android Apps

Getting Started

Create New Project What is Activity? What is Fragment?

Page 8: Developing Android Apps

Activity & Fragment

What is Activity? http://developer.android.com/reference/android/app/Activity.html Activity Lifecycle

Page 9: Developing Android Apps

Activity & Fragment

What is Activity? http://developer.android.com/reference/android/app/Activity.html 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(); }

Page 10: Developing Android Apps

Activity & Fragment

What is Activity? http://developer.android.com/reference/android/app/Activity.html Starting Activities and Getting Results

public class MyActivity extends Activity {     ...

     static final int PICK_CONTACT_REQUEST = 0;

     public boolean onKeyDown(int keyCode, KeyEvent event) {         if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {             // When the user center presses, let them pick a contact.             startActivityForResult(                 new Intent(Intent.ACTION_PICK,                 new Uri("content://contacts")),                 PICK_CONTACT_REQUEST);            return true;         }         return false;     }

     protected void onActivityResult(int requestCode, int resultCode,             Intent data) {         if (requestCode == PICK_CONTACT_REQUEST) {             if (resultCode == RESULT_OK) {                 // A contact was picked.  Here we will just display it                 // to the user.                 startActivity(new Intent(Intent.ACTION_VIEW, data));             }         }     } }

Page 11: Developing Android Apps

Activity & Fragment

What is Fragment? http://developer.android.com/guide/components/fragments.html

Page 13: Developing Android Apps

Activity & Fragment

What is Fragment? http://developer.android.com/guide/components/fragments.html For example, here's a subclass of Fragment that loads a layout from

the example_fragment.xml file: public static class ExampleFragment extends Fragment {    @Override    public View onCreateView(LayoutInflater inflater, ViewGroup container,                             Bundle savedInstanceState) {        // Inflate the layout for this fragment        return inflater.inflate(R.layout.example_fragment, container, false);    }}

Page 14: Developing Android Apps

Activity & Fragment

What is Fragment? http://developer.android.com/guide/components/fragments.html Declare the fragment inside

the activity’s layout file

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="horizontal"    android:layout_width="match_parent"    android:layout_height="match_parent">    <fragment android:name="com.example.news.ArticleListFragment"            android:id="@+id/list"            android:layout_weight="1"            android:layout_width="0dp"            android:layout_height="match_parent" />    <fragment android:name="com.example.news.ArticleReaderFragment"            android:id="@+id/viewer"            android:layout_weight="2"            android:layout_width="0dp"            android:layout_height="match_parent" /></LinearLayout>

Page 15: Developing Android Apps

Activity & Fragment

What is Fragment? http://developer.android.com/guide/components/fragments.html Or, programmatically add the fragment to an existing ViewGroup To make fragment transactions in your activity (such as add, remove, or replace a

fragment), you must use APIs from FragmentTransaction. You can get an instance of FragmentTransaction from your Activitylike this:

You can then add a fragment using the add() method, specifying the fragment to add and the view in which to insert it. For example:

FragmentManager fragmentManager = getFragmentManager()FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

ExampleFragment fragment = new ExampleFragment();fragmentTransaction.add(R.id.fragment_container, fragment);fragmentTransaction.commit();

Page 16: Developing Android Apps

Activity & Fragment

What is Fragment? http://developer.android.com/guide/components/fragments.html

Page 17: Developing Android Apps

Start your own project

You have your own project!

Page 18: Developing Android Apps

Bug & Trouble Shooting

Problems Installing HAXM

Page 20: Developing Android Apps

Bug & Trouble Shooting

Problem Resizing Android Emulator on Windows 8.1 AVD is out of view on Windows

Page 21: Developing Android Apps

Bug & Trouble Shooting

How to Solve It on Android Studio Click Run

Edit Configurations General Tab

Choose Emulator and AVD

Page 22: Developing Android Apps

Bug & Trouble Shooting

How to Solve It on Android Studio Click Emulator Tab

Write –scale 0.x ( In this case, 0.4 was suitable )

Page 23: Developing Android Apps

Bug & Trouble Shooting

How to Solve It by Using Telnet Click Control Panel

Go to Programs Turn Windows features on or off

Page 24: Developing Android Apps

Bug & Trouble Shooting

How to Solve it by Using Telnet Run your application on Android Virtual

Device Run CMD in Windows

Write cd/ to go back to C drive directory Use the command ‘telnet localhost

5554’ to connect Android Emulator

Page 25: Developing Android Apps

Bug & Trouble Shooting

How to Solve it by Using Telnet Use the command ‘help’ to see the

Android console command list Use the command ‘window scale 0.x’

Page 26: Developing Android Apps

To be ContinueAUGUST 2015