This file contains hidden or 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 | |
public boolean onOptionsItemSelected(MenuItem item) { | |
switch(item.getItemId()) { | |
/* | |
* Typically, an application registers automatically, so options | |
* below are disabled. Uncomment them if you want to manually | |
* register or unregister the device (you will also need to | |
* uncomment the equivalent options on options_menu.xml). | |
*/ | |
// 以下2つのcaseをコメントインする。 |
This file contains hidden or 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 onMessage(Context context, Intent intent) { | |
Log.i(TAG, "Received message"); | |
// intent から取得して表示する文字列に結合 | |
Bundle extras = intent.getExtras(); | |
String result = extras.getString("message"); | |
String message = getString(R.string.gcm_message) + " = " + result; |
This file contains hidden or 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
File file = new File(ファイルパス); // 他アプリに渡すファイル | |
Intent intent = new Intent(Intent.ACTION_SEND); // データーを送信するインテント | |
intent.setType("image/png"); // データタイプの指定 | |
intent.putExtra(Intent.EXTRA_SUBJECT, "件名"); | |
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); | |
startActivity(intent); |
This file contains hidden or 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 | |
implements FragmentA.OnArtcleListener { | |
// コールバックを受け取るインターフェース | |
@Override | |
public void onArticleSelected(Uri articleUri) { | |
// 受け取ったUriで、別のView(フラグメント)を操作する | |
// ... | |
This file contains hidden or 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
<!-- | |
ShareActionProvider | |
android.support.v7.widget.ShareActionProvider | |
--> | |
<menu xmlns:android="http://schemas/android.com/apk/res/android" | |
xmlns:yourapp="http://schemas.android.com/apk/res-auto"> | |
<item | |
android:id="@+id/menu_share" | |
android:title="@string/menu_share" | |
yourapp:actionProviderClass="android.support.v7.widget.ShareActionProvider" |
This file contains hidden or 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
/* | |
ShareActionProvider | |
android.support.v7.widget.ShareActionProvider | |
*/ | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu | |
getMenuInflater().inflate(R.menu.main_memu, menu); | |
This file contains hidden or 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
final Handler handler = new Handler(new Handler.Callback() { | |
@Override | |
public boolean handleMessage(Message msg) { | |
switch(msg.what) { | |
case RESULT_WHAT: | |
handleResult((Result) msg.obj); | |
return true; | |
} | |
return false; | |
} |
This file contains hidden or 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 DownloadFilesTask extends AsyncTask<Void, Integer, Result> { | |
@Override | |
protected void onPreExecute() { | |
// Something like showing a progress bar | |
} | |
@Override | |
protected Result doInBackground(Void... params) { | |
Result result = new Result(); |
This file contains hidden or 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
/* | |
1.6 以前は、シングルスレッドで順番に実行される | |
1.6 から 2.3、スレッドプールで並列に実行される。 | |
3.0 以降、デフォルトで以前の動作に戻る。スレッドプール利用はexecuteOnExecutor()で。 | |
今どきの端末ではデフォルトでは並列実行されない。 | |
*/ | |
public class ConcurrentAsyncTask { | |
public static void execute(AsyncTask as) { | |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { | |
as.execute(); |