Saturday, April 09, 2011
alertDialog Android-ban
Innen:
Message box with buttons
Simple message box with no buttons
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Packing List");
alertDialog.setMessage("Could not find the file.");
alertDialog.show();
Message box with buttons
AlertDialog deleteAlert = new AlertDialog.Builder(this).create();
deleteAlert.setTitle("Delete List");
deleteAlert.setMessage("Are you sure you want to delete this list?");
deleteAlert.setButton("Yes", new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
//...
}
});
deleteAlert.setButton2("No", new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
//...
}
});
deleteAlert.show();
Friday, April 08, 2011
Brad Fitzpatrick: Writing zippy Android apps
• What is an ANR? Why do you see them?
• Quantifying responsiveness: “jank”
• Android SDK features to use to avoid jankiness & ANRs
• Numbers to know
• War stories from optimizing Froyo (2.2)
• New performance instrumentation available in Froyo
A service-eket deklaralni kell a manifest-ben
Ezt kihagytam es ezert nem hivodott meg az IntentService-em, bar latvanyos hiba nem tortent csak a log-ban lattam, hogy "Unable to start service Intent XXX: not found"
Monday, April 04, 2011
Ha az Activity-t csak Landscape akarjuk latni
Akkor az onCreate(Bundle savedInstances)-be kell beleirni ezt:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mondjuk a a setContentView(..) ele.
Persze mas screenOrientation-t is valaszthatunk.
Friday, April 01, 2011
Create folder/file on Android
Legalabbis a Samsung Galaxy S-en ezt tapasztaltam:
Az Eclipse File Explorer-eben is lathato az /mnt/sdcard/ folder. Ezen belul van egy external_sd ami mindig jelen van, de csak akkor hasznalhato, ha tenyleg beteszunk egy kulcso SD Card-ot a telefonba.
Ami videokat/kepeket a default Camera app-al rogzitunk az a
/mnt/sdcard/DCIM/Camera/video-yyyy-mm-dd-hh-mm-ss.mp4
illetve
/mnt/sdcard/DCIM/Camera/yyy-mm-dd hh.mm.ss.jpg
file-ba kerulnek.
Ha kodbol letrehuzzuk az "/folder/foo" folder-t, akkor az itt lesz:
/mnt/sdcard/foo
es nem torlodik, ha letoroljuk az app-ot ami csinlata.
Ezzel a koddal keszult:
File newDirectory = new File("/sdcard/foo/");
newDirectory.mkdirs();
getFilesDir() azt a folder-t adja vissza ahova az app irhat. Ez a folder az app torlesenel automatikusan torlodik es csak az adott app fer hozza.
Valahogy igy nez ki: /data/data/com.example.foo/files/
getExternalFilesDir(String type) is egy olyan folder-t ad vissza, ahova az app irhat csak ez az external SD kartyan. A dokumentacio szerint "These files are private to the applications, and not typically visible to the user as media" de nem tudom a "typically" itt mit jelent. A getFiles()-al szemben viszont "There is no security enforced with these files. All applications can read and write files placed here."
Valahogy igy nez ki: /mnt/sdcard/external_sd/Android/data/com.example.foo/files/
Tehat az /mnt/sdcard/external_sd/ ezert el akkor is, ha nincs a telefonban kulso SD kartya es nyugodtan lehet is hasznalni ezzel a method-dal. Peldaul letrehozni benne sajat bar konyvtarat a foo app konyvtara ala:
File efd = getExternalFilesDir(null);
File barFolder = new File(efd.getAbsolutePath() + "/bar/");
barFolder.mkdirs();
Ez igy rendben mukodik, de amikor uninstallaltam a foo app-ot, akkor sem torlodott az /mnt/sdcard/external_sd/Android/data/com.example.foo/files folder. Pedig a dokumentacio szerint: "This is like
getFilesDir()
in that these files will be deleted when the application is uninstalled"A type parameter pedig erre jo: "The type of files directory to return. May be null for the root of the files directory or one of the following Environment constants for a subdirectory:
DIRECTORY_MUSIC
,DIRECTORY_PODCASTS
, DIRECTORY_RINGTONES
, DIRECTORY_ALARMS
, DIRECTORY_NOTIFICATIONS
, DIRECTORY_PICTURES
, or DIRECTORY_MOVIES
"getExternalStorageDirectory(): "don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer."
"Any files that are private to the application should be placed in a directory returned by
Context.getExternalFilesDir
, which the system will take care of deleting if the application is uninstalled. Other shared files should be placed in one of the directories returned by getExternalStoragePublicDirectory(String)."
Subscribe to:
Posts (Atom)