developing android apps

Post on 14-Apr-2017

358 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Developing Android AppsFOR FUN!CLAIRE HYUNJUNG LEE

Contens

Getting Started

Activity and Fragment

Start Your Own Project

Bug and Trouble Shooting

Getting Started

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

Getting Started

Create New Project Let’s start your own project

Getting Started

Create New Project What is Activity? What is Fragment?

Activity & Fragment

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

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(); }

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));             }         }     } }

Activity & Fragment

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

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);    }}

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>

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();

Activity & Fragment

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

Start your own project

You have your own project!

Bug & Trouble Shooting

Problems Installing HAXM

Bug & Trouble Shooting

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

Bug & Trouble Shooting

How to Solve It on Android Studio Click Run

Edit Configurations General Tab

Choose Emulator and AVD

Bug & Trouble Shooting

How to Solve It on Android Studio Click Emulator Tab

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

Bug & Trouble Shooting

How to Solve It by Using Telnet Click Control Panel

Go to Programs Turn Windows features on or off

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

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’

To be ContinueAUGUST 2015

top related