Refine search
// 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);
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); } }
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); } }
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); } }
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); }
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(); } } }
/** * 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)); } }); }
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); }
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;
@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); } });
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
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));
@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); }