【Android】各種インスタンス生成書式 のまとめ

EngineeringAndroid, 備忘録, 試験

【Android】オブジェクト取得式、インスタンス生成式、定義式(シグニチャ)

Android_instances

Android 技術者認定試験ベーシックの教材を元に書式をいくつかまとめる。

 

 

new 系

[explicit intent]
Intent i = new Intent(getApplicationContext(), CalledActivity.class);
startActivity(i);

 

[ Dialog ]
AlertDialog,Builder b = new AlertDialog.Builder(this);

 

[ Adapter set-list-data ]
ArrayAdapter<String> ad = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, stringArray);
setListAdapter(ad);

 

[ database preparation ]
SampleDBHelper sH = new SampleDBHelper(this, “Sample.db”, null, 1);

 

[ progress dialog ]
ProgressDialog pd = new ProgressDialog(this);
dialog.show();

 

[ notification ]
Notification nt = new Notification(icon, msg, when);

 

 

 

get 系

[ Wifi ]
WifiManager wM = (WifiManager)getSystemService(Context.WIFI_SERVICE);

 

[ SensorManager ]
SensorManager sM = (SensorManager)getSystemService(Context.SENCER_SERVICE);
List<Sensor> sL = sM.getSensorList(Sensor.TYPE_ACCELEROMETER);

 

[ implicit intent ]
Intent i = getIntent();
TextView tV = (TextView) findViewById(R.id.textview);

 

[ OptionMenu ]
MenuInflater inf = getMenuInflater();
inf.inflate(R.menu.game_menu, menu);

 

[ Adapter get-ListView ]
ListView lV = getListView();
lV.setAdapter(ad);

 

[ Bluetooth ]
Bluetooth bT = BluetoothAdapter.getDefaultAdapter();

 

[ database operation ]
SQLiteDatabase db = sH.getWritableDatabase();

 

[ Preference file ]
SharedPreferences sP = getPreferences(MODE_PRIVATE);

 

[ content provider ]
ContentResolver r = getContentResolver();
Cursor c = r.query(ContactsContact.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);

 

[ notification ]
NotificationManager nm = (NotificationManager)getSystemService(Context, NOTIFICATION_SERVICE);
nm.notify(id, nt);

 

 

 

file output

FileOutputStream fos = openFileOutput(“sample.txt”, MODE_WORLD_WRITABLE);

 

File input

FileInputStream fis = openFileInput(“sample.txt”);

 

 

 


KENスクール[ピーシーキョウシツ]

EngineeringAndroid, 備忘録, 試験

Posted by Qawai