Skip to content

Instantly share code, notes, and snippets.

@kuwapp
kuwapp / 0_reuse_code.js
Created November 19, 2015 02:57
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
/**
* Created by yusukehata on 2015/03/01.
*/
public class AsyncTaskTest extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final MyAsyncTask asyncTask = new MyAsyncTask();
asyncTask.execute("");
<application>
//略
<receiver
android:name=".NotificationReceiver"
android:process=":remote"/>
//略
</application>
public class NotificationReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
String message = intent.getStringExtra("MESSAGE");
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
public class NotificationUtil {
public static void setLocalNotification(Context context, String message, int requestCode, int interval){
Intent intent = new Intent(context, NotificationReceiver.class);
intent.putExtra("MESSAGE", message);
PendingIntent sender = PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, interval);
//HOGEスレッド開始
HogeThread thread = new HogeThread();
thread.start();
//再利用できないのでインスタンス生成
thread = new HogeThread();
thread.start();
//はじめに起動するActivity内でリソースを読み込んでおく
//一度読み込めば以降呼ぶ必要はない
StringResource.LoadResrouce(getApplicationContext());
//文字列を取得
String appName = StringResource.getString(R.string.KuwApp);
String blogTitle = StringResource.getString(R.string.blog_title);
String blogUrl = StringResource.getString(R.string.blog_url);
public class StringResource {
private static HashMap< Integer, String> stringResources = null;
public static void LoadResrouce(Context context){
stringResources = new HashMap< Integer, String>();
Field[] fields = R.string.class.getFields();
for(Field field:fields) {
try {
public class MyPagerAdapter extends FragmentPagerAdapter{
//いろいろ略
@Override
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
bundle.putInt("INDEX", position);