onSaveInstanceState() onRestoreInstanceState() basic Android example
public class MyClass extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
String sMyText = "some text";
int nMyInt = 10;
@Override
protected void onSaveInstanceState(Bundle outState) {
// Save away the original text, so we still have it if the activity
// needs to be killed while paused.
outState.putString("my_text", sMyText);
outState.putInt("my_int", nMyInt);
Toast.makeText(this, "onSaveInstanceState()", Toast.LENGTH_LONG).show();
Log.i("onSaveInstanceState", "onSaveInstanceState()");
}
String sNewMyText = "";
int nNewMyInt = 0;
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// restore saved values
sNewMyText = savedInstanceState.getString("my_text");
nNewMyInt = savedInstanceState.getInt("my_int");
Toast.makeText(this, "onRestoreInstanceState()", Toast.LENGTH_LONG).show();
Log.i("onRestoreInstanceState", "onRestoreInstanceState()");
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
If you want download some *.apk file from internet and try on your emulator you get error than you have to install SD card. You have to closing Android emulator.
Mount Android emulator SD card instruction
Image how install SD card on Android emulator in Eclipse.
Mount Android emulator SD card instruction
- In Eclipse go in menu Window - Android SDK and Avg Manager
- Select Virtual devices
- Select AVD Name where you need install SD card
- Click on Edit button
- In open dialog go to SD card - Size: and write 500
- Press button Edit AVD
- Run AVD emulator
Image how install SD card on Android emulator in Eclipse.
ImputStream is = this.getResources().openRawResource(R.drawable.colors);
Bitmap mBitmap2 = BitmapFactory.decodeStream(is);
int w = mBitmap2.getWidth();
int h = mBitmap2.getHeight();
// int x , y have to be smaller as w , h
int _color = mBitmap2.getPixel(x, y);
StringBuilder, res/raw folder, try catch finaly throws, BufferedReader, InputStream, openRawResource, getResources Android example
MainActivity.java
MainActivity.java
public class MainActivity extends Activity {
TextView txtV;
Context cntx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtV = (TextView)findViewById(R.id.idLabel);
cntx = this;
try {
StringBuilder strBuilder = myFunction(cntx);
txtV.setText(strBuilder);
} catch (IOException e) {
e.printStackTrace();
}
}
private StringBuilder myFunction(Context context) throws IOException {
final Resources resources = context.getResources();
InputStream inputStream = resources.openRawResource(R.raw.my_file);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder strBuild = new StringBuilder();
try {
String line;
while ((line = reader.readLine()) != null) {
strBuild.append(line);
}
} finally {
reader.close();
}
return strBuild;
}
}
Motorola Droid X cena od 3 000 KCZ Kč (únor.2012)
Spokojenost uživatelů nadprůměrná.
Motorola Droid X je chytrý telefon s operačním systémem Android.
Motorola Droid X je (22.února2012) 8. nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.
Android 2.1
Display 854 x 480 pixelů
8 megapixel fotoaparát dual LED flash
720p HD video recording
Music and Video player
8 GB paměť
rozšíření paměti 32 GB
WiFi/DLNA
TI OMAP3630 processor – 1GHz
4.3-inch large display
Motorola Droid X photo pic image
Zdroj obrázku: wikipedia
Spokojenost uživatelů nadprůměrná.
Motorola Droid X je chytrý telefon s operačním systémem Android.
Motorola Droid X je (22.února2012) 8. nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.
Android 2.1
Display 854 x 480 pixelů
8 megapixel fotoaparát dual LED flash
720p HD video recording
Music and Video player
8 GB paměť
rozšíření paměti 32 GB
WiFi/DLNA
TI OMAP3630 processor – 1GHz
4.3-inch large display
Motorola Droid X photo pic image
Zdroj obrázku: wikipedia
If project is in workspace and only not visible in project explorer using this:
Click on some project in project explorer
Menu:
File
Import project
Existing Projects into Workspace
Editace: 2011-10-08 15:38:52
Počet článků v kategorii: 396
Url:onsaveinstancestate-onrestoreinstancestate-basic-android-example