5. startActivity
public class A extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.a);
}
public void click(View v) {
Intent i = new Intent(this, B.class);
startActivity(i);
}
}
9. startActivity
こう変えたらどうなる?
public class A extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.a);
}
public void click(View v) {
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.google.com/"));
startActivity(i);
}
}
10. Intent
• An intent is an abstract description of an
operation to be performed.
• 「Intentとは実行される操作の抽象的な単位です。」
▫ 一つのアクティビティ内のウィジェットやイベントは単
一のスレッドで実行される
▫ Handlerドリブン、Looperでのループ
▫ でも、そうとは限らないので、画面遷移をはじめとする
あらゆるコンポーネント間連携を隠ぺいする(開発者
が楽になり、繋がりやすくなる)
18. static
•staticな入れ物(クラス変数)に入れ
ておけばいい
public class A extends Activity {
static int val;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.a);
}
public void click(View v) {
System.out.println(++val);
}
}
25. ファイルに保存
•android.context.Context
•abstract FileInputStream openFileInput(String name)
Open a private file associated with this Context's application package for
reading.
•abstract FileOutputStream openFileOutput(String name, int mode)
Open a private file associated with this Context's application package for
writing.
•普通にjava.ioでもできます。(アクセスできる場所なら)
26. キャッシュ
•android.context.Context#
getCacheDir()
•public abstract File getCacheDir ()
Returns the absolute path to the
application specific cache directory on the
filesystem.
31. Can I ask?
•気を付けるべきことは?
デカくなると遅くなる(XML)
複数プロセスからのアクセ
スは同期化されない
Note: currently this class does not support use
across multiple processes. This will be added later.
など