本文整理了Java中android.os.Handler.<init>()
方法的一些代码示例,展示了Handler.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Handler.<init>()
方法的具体详情如下:
包路径:android.os.Handler
类名称:Handler
方法名:<init>
暂无
代码示例来源:origin: stackoverflow.com
// initialize the progress dialog like in the first example
// this is how you fire the downloader
mProgressDialog.show();
Intent intent = new Intent(this, DownloadService.class);
intent.putExtra("url", "url of the file to download");
intent.putExtra("receiver", new DownloadReceiver(new Handler()));
startService(intent);
代码示例来源:origin: stackoverflow.com
mProgressDialog.show();
Intent intent = new Intent(this, DownloadService.class);
intent.putExtra("url", "url of the file to download");
intent.putExtra("receiver", new DownloadReceiver(new Handler()));
startService(intent);
代码示例来源:origin: stackoverflow.com
Intent i = new Intent(this, DownloadService.class);
i.putExtra("receiver", new DownReceiver(new Handler()));
<context>.startService(i);
代码示例来源:origin: stackoverflow.com
public class MyActivity extends ListActivity {
private MyResultReceiver theReceiver = null;
...
private void callService () {
theReceiver = new MyResultReceiver(new Handler());
theReceiver.setParentContext(this);
Intent i = new Intent("com.mycompany.ACTION_DO_SOMETHING");
// Code to define and initialize myData here
i.putExtra("someData", myData);
i.putExtra("resReceiver", theReceiver);
startService(i);
}
}
代码示例来源:origin: stackoverflow.com
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class Splash extends Activity {
/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 1000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splashscreen);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,Menu.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
}
代码示例来源:origin: stackoverflow.com
public class Splash extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
int secondsDelayed = 1;
new Handler().postDelayed(new Runnable() {
public void run() {
startActivity(new Intent(Splash.this, ActivityB.class));
finish();
}
}, secondsDelayed * 1000);
}
}
代码示例来源:origin: stackoverflow.com
public class SplashScreen extends Activity {
private static final int SPLASH_DISPLAY_TIME = 4000; // splash screen delay time
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent();
intent.setClass(Splash.this, NextActivity.class);
Splash.this.startActivity(intent);
Splash.this.finish();
// transition from splash to main menu
overridePendingTransition(R.animate.activityfadein,
R.animate.splashfadeout);
}
}, SPLASH_DISPLAY_TIME);
}
代码示例来源:origin: stackoverflow.com
public class SplashActivity extends Activity {
private static boolean splashLoaded = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!splashLoaded) {
setContentView(R.layout.activity_splash);
int secondsDelayed = 1;
new Handler().postDelayed(new Runnable() {
public void run() {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
}, secondsDelayed * 500);
splashLoaded = true;
}
else {
Intent goToMainActivity = new Intent(SplashActivity.this, MainActivity.class);
goToMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(goToMainActivity);
finish();
}
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
/**
* A simple and general error handler that show a Toast for known exceptions, and for others, opens the report error activity with the (optional) error message.
*/
public static void handleGeneralException(Context context, int serviceId, String url, Throwable exception, UserAction userAction, String optionalErrorMessage) {
final Handler handler = new Handler(context.getMainLooper());
handler.post(() -> {
if (exception instanceof ReCaptchaException) {
Toast.makeText(context, R.string.recaptcha_request_toast, Toast.LENGTH_LONG).show();
// Starting ReCaptcha Challenge Activity
Intent intent = new Intent(context, ReCaptchaActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} else if (exception instanceof IOException) {
Toast.makeText(context, R.string.network_error, Toast.LENGTH_LONG).show();
} else if (exception instanceof YoutubeStreamExtractor.GemaException) {
Toast.makeText(context, R.string.blocked_by_gema, Toast.LENGTH_LONG).show();
} else if (exception instanceof ContentNotAvailableException) {
Toast.makeText(context, R.string.content_not_available, Toast.LENGTH_LONG).show();
} else {
int errorId = exception instanceof YoutubeStreamExtractor.DecryptException ? R.string.youtube_signature_decryption_error :
exception instanceof ParsingException ? R.string.parsing_error : R.string.general_error;
ErrorActivity.reportError(handler, context, exception, MainActivity.class, null, ErrorActivity.ErrorInfo.make(userAction,
serviceId == -1 ? "none" : NewPipe.getNameOfService(serviceId), url + (optionalErrorMessage == null ? "" : optionalErrorMessage), errorId));
}
});
}
代码示例来源:origin: iSoron/uhabits
public void restartWithFade(Class<?> cls)
{
new Handler().postDelayed(() ->
{
finish();
overridePendingTransition(fade_in, fade_out);
startActivity(new Intent(this, cls));
}, 500); // HACK: Let the menu disappear first
}
代码示例来源:origin: LawnchairLauncher/Lawnchair
public static void callAsync(Context context, String[] permissions, int requestCode, final PermissionResultCallback callback) {
// Proceed to the callback if permissions were already granted
if (PermissionResponse.hasPermissions(context, permissions)) {
callback.onComplete(new PermissionResponse(permissions, new int[]{PackageManager.PERMISSION_GRANTED}, requestCode));
return;
}
// Our result receiver to get the response asynchronously
ResultReceiver receiver = new ResultReceiver(new Handler(Looper.getMainLooper())) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
int[] grantResult = resultData.getIntArray("grantResult");
String[] permissions = resultData.getStringArray("permissions");
// Call the callback with the result
callback.onComplete(new PermissionResponse(permissions, grantResult, resultCode));
}
};
// Build our intent to launch
Intent intent = new Intent(context, PermissionActivity.class);
intent.putExtra("requestCode", requestCode);
intent.putExtra("permissions", permissions);
intent.putExtra("resultReceiver", receiver);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
// Start our activity and wait
context.startActivity(intent);
}
代码示例来源:origin: stackoverflow.com
setContentView(R.layout.activity_main);
receiver = new MyReceiver(new Handler()); // Create the receiver
registerReceiver(receiver, new IntentFilter("some.action")); // Register receiver
sendBroadcast(new Intent("some.action")); // Send an example Intent
代码示例来源:origin: stackoverflow.com
LayoutInflater li = LayoutInflater.from(context);
final View view = li.createView(name, null, attrs);
new Handler().post(new Runnable() {
public void run() {
switch (item.getItemId()) {
case R.id.AboutUs:
Intent i = new Intent("com.test.demo.ABOUT");
startActivity(i);
break;
case R.id.preferences:
Intent p = new Intent("com.test.demo.PREFS");
startActivity(p);
break;
代码示例来源:origin: aa112901/remusic
@Override
public void onItemMoved(int from, int to) {
Log.d("queue", "onItemMoved " + from + " to " + to);
MusicInfo musicInfo = mAdapter.getMusicAt(from);
boolean f = mAdapter.isItemChecked(from);
boolean t = mAdapter.isItemChecked(to);
mAdapter.removeSongAt(from);
mAdapter.setItemChecked(from, t);
mAdapter.addSongTo(to, musicInfo);
mAdapter.setItemChecked(to, f);
mAdapter.notifyDataSetChanged();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
pManager.delete(playlistId);
for (int i = 0; i < mAdapter.mList.size(); i++) {
pManager.insert(PlaylistSelectActivity.this, playlistId, mAdapter.mList.get(i).songId, i);
}
}
}, 100);
//MusicPlayer.moveQueueItem(from, to);
Intent intent = new Intent();
intent.setAction(IConstants.PLAYLIST_ITEM_MOVED);
PlaylistSelectActivity.this.sendBroadcast(intent);
}
});
代码示例来源:origin: naman14/Timber
case R.id.nav_nowplaying:
if (getCastSession() != null) {
startActivity(new Intent(MainActivity.this, ExpandedControlsActivity.class));
} else {
NavigationUtils.navigateToNowplaying(MainActivity.this, false);
case R.id.nav_about:
mDrawerLayout.closeDrawers();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
startActivity(new Intent(MainActivity.this, DonateActivity.class));
break;
menuItem.setChecked(true);
mDrawerLayout.closeDrawers();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
代码示例来源:origin: aa112901/remusic
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(MediaService.PLAYLIST_CHANGED);
sendBroadcast(intent);
mAdapter.updateDataSet();
mAdapter.notifyDataSetChanged();
SelectActivity.this.sendBroadcast(new Intent(IConstants.MUSIC_COUNT_CHANGED));
代码示例来源:origin: wangdan/AisenWeiBo
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_HOME);
new Handler().postDelayed(new Runnable() {
代码示例来源:origin: aa112901/remusic
case 0:
if (adapterMusicInfo.islocal) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
break;
case 2:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + adapterMusicInfo.data));
public void run() {
PlaylistsManager.getInstance(mContext).deleteMusic(mContext, adapterMusicInfo.songId);
mContext.sendBroadcast(new Intent(IConstants.MUSIC_COUNT_CHANGED));
代码示例来源:origin: stackoverflow.com
mResultReceiver = new AddressResultReceiver(new Handler());
Intent intent = new Intent(this, FetchAddressIntentService.class);
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = N)
public void cancel_removesMatchingListeners() {
Intent intent = new Intent("ACTION!");
PendingIntent pI = PendingIntent.getService(context, 1, intent, 0);
OnAlarmListener listener1 = () -> {};
OnAlarmListener listener2 = () -> {};
Handler handler = new Handler();
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 20, "tag", listener1, handler);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 30, "tag", listener2, handler);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 40, pI);
assertThat(shadowAlarmManager.getScheduledAlarms()).hasSize(3);
alarmManager.cancel(listener1);
assertThat(shadowAlarmManager.getScheduledAlarms()).hasSize(2);
assertThat(shadowAlarmManager.peekNextScheduledAlarm().onAlarmListener).isEqualTo(listener2);
assertThat(shadowAlarmManager.peekNextScheduledAlarm().handler).isEqualTo(handler);
}
内容来源于网络,如有侵权,请联系作者删除!