Created
December 8, 2012 00:39
-
-
Save a-thomas/4237852 to your computer and use it in GitHub Desktop.
Formation Android 1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class ParlezVousTask extends AsyncTask<String, Void, Boolean> { | |
@Override | |
protected void onPreExecute() { | |
// exécuté dans l'UIThread | |
} | |
@Override | |
protected Boolean doInBackground(String... params) { | |
// exécuté sur un autre thread | |
return true; | |
} | |
@Override | |
protected void onPostExecute(Boolean result) { | |
// exécuté dans l'UIThread | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// envoyer un broadcast | |
Intent intent = new Intent(); | |
intent.setAction("com.excilys.formation.MY_OWN_BROADCAST"); | |
sendBroadcast(intent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
DefaultHttpClient client = new DefaultHttpClient(); | |
HttpGet request = new HttpGet("http://www.google.com"); | |
HttpResponse response = client.execute(request); | |
InputStream content = response.getEntity().getContent(); | |
// ... | |
} catch (ClientProtocolException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Intent intent = new Intent(this, MyActivity.class); | |
startActivity(intent); | |
// ou | |
Intent intent = new Intent(); | |
intent.setAction("com.excilys.formation.MY_OWN_ACTION"); | |
startActivity(intent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ParlezVousActivity extends Activity { | |
private final String TAG = ParlezVousActivity.class.getSimpleName(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity { | |
private TextView myTextView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
myTextView = (TextView) findViewById(R.id.my_text_view); | |
myTextView.setText(R.string.hello_world); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity" > | |
<TextView | |
android:id="@+id/my_text_view" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_centerHorizontal="true" | |
android:layout_centerVertical="true" | |
android:text="@string/hello_world" /> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<string name="app_name">Example</string> | |
<string name="hello_world">Hello world!</string> | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class R { | |
public static final class attr { | |
} | |
public static final class drawable { | |
public static final int ic_launcher=0x7f020000; | |
} | |
public static final class id { | |
public static final int my_text_view=0x7f070000; | |
} | |
public static final class layout { | |
public static final int activity_main=0x7f030000; | |
} | |
public static final class string { | |
public static final int app_name=0x7f040000; | |
public static final int hello_world=0x7f040001; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
// Juste un exemple, retient nombre | |
outState.putInt("NUMBER", 4); | |
} | |
@Override | |
protected void onRestoreInstanceState(Bundle savedInstanceState) { | |
super.onRestoreInstanceState(savedInstanceState); | |
// La nouvelle Activity créée peut récupérer ce nombre | |
int selectedIndex = savedInstanceState.getInt("NUMBER"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment