android.content.Context.startActivity()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(194)

本文整理了Java中android.content.Context.startActivity()方法的一些代码示例,展示了Context.startActivity()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.startActivity()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:startActivity

Context.startActivity介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public void startNewActivity(Context context, String packageName) {
  Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
  if (intent != null) {
    // We found the activity now start the activity
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
  } else {
    // Bring user to the market or let them choose an app?
    intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(Uri.parse("market://details?id=" + packageName));
    context.startActivity(intent);
  }
}

代码示例来源:origin: JessYanCoding/MVPArms

public static void openDail(Context context) {
  Intent intent = new Intent(Intent.ACTION_DIAL);
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  context.startActivity(intent);
}

代码示例来源:origin: LitePalFramework/LitePal

public static void actionStart(Context context, String className) {
  Intent intent = new Intent(context, ModelStructureActivity.class);
  intent.putExtra(CLASS_NAME, className);
  context.startActivity(intent);
}

代码示例来源:origin: stackoverflow.com

try {
  locationManager = (LocationManager) mContext
      .getSystemService(LOCATION_SERVICE);
      .isProviderEnabled(LocationManager.GPS_PROVIDER);
      .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog,int which) {
    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    mContext.startActivity(intent);

代码示例来源:origin: k9mail/k-9

public static void listAccounts(Context context) {
  Intent intent = new Intent(context, Accounts.class);
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP |
      Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
  intent.putExtra(EXTRA_STARTUP, false);
  context.startActivity(intent);
}

代码示例来源:origin: Neamar/KISS

@Override
  public void doLaunch(Context context, View v) {
    try {
      if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
        assert launcher != null;
        launcher.startMainActivity(className, appPojo.userHandle.getRealHandle(), v.getClipBounds(), null);
      } else {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setComponent(className);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
          intent.setSourceBounds(v.getClipBounds());
        }

        context.startActivity(intent);
      }
    } catch (ActivityNotFoundException | NullPointerException e) {
      // Application was just removed?
      // (null pointer exception can be thrown on Lollipop+ when app is missing)
      Toast.makeText(context, R.string.application_not_found, Toast.LENGTH_LONG).show();
    }
  }
}

代码示例来源:origin: stackoverflow.com

...
Context context = this.getApplicationContext();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(30);        
for (ActivityManager.RunningTaskInfo task:tasks) {
  if (task.baseActivity.getShortClassName().equals(".MainActivity")) {    
    try {
      Intent launchTopIntent = new Intent(context, Class.forName(task.topActivity.getClassName()));
        context.startActivity(launchTopIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));             
    } catch (ClassNotFoundException ex) {
      Logger.getLogger(CashWidgetProvider.class.getName()).log(Level.SEVERE, null, ex);
    }                  
  }
} 
...

代码示例来源:origin: stackoverflow.com

_intent = intent;
locationManager = (LocationManager) context
    .getSystemService(Context.LOCATION_SERVICE);
if (locationManager.isProviderEnabled(provider)) {
  locationManager.requestLocationUpdates(provider,
      MIN_TIME_REQUEST, 5, locationListener);
  Intent settinsIntent = new Intent(
      android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  settinsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  _context.startActivity(settinsIntent);

代码示例来源:origin: yhaolpz/FloatWindow

private static void reqForMiui67(Context context) {
  Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
  intent.setClassName("com.miui.securitycenter",
      "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
  intent.putExtra("extra_pkgname", context.getPackageName());
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  if (isIntentAvailable(intent, context)) {
    context.startActivity(intent);
  } else {
    LogUtil.e("intent is not available!");
  }
}

代码示例来源:origin: fennifith/Alarmio

@Override
  public void onReceive(Context context, Intent intent) {
    AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Alarmio alarmio = (Alarmio) context.getApplicationContext();
    AlarmData alarm = alarmio.getAlarms().get(intent.getIntExtra(EXTRA_ALARM_ID, 0));
    if (alarm.isRepeat())
      alarm.set(context, manager);
    else alarm.setEnabled(alarmio, manager, false);
    alarmio.onAlarmsChanged();

    Intent ringer = new Intent(context, AlarmActivity.class);
    ringer.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ringer.putExtra(AlarmActivity.EXTRA_ALARM, alarm);
    context.startActivity(ringer);
  }
}

代码示例来源:origin: iTXTech/Daedalus

@Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION)) {
      Daedalus.deactivateService(context);
    }
    if (intent.getAction().equals(STATUS_BAR_BTN_SETTINGS_CLICK_ACTION)) {
      Intent settingsIntent = new Intent(context, MainActivity.class).putExtra(MainActivity.LAUNCH_FRAGMENT, MainActivity.FRAGMENT_SETTINGS);
      settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(settingsIntent);
      try {
        Object statusBarManager = context.getSystemService("statusbar");
        Method collapse = statusBarManager.getClass().getMethod("collapsePanels");
        collapse.invoke(statusBarManager);
      } catch (Exception e) {
        Logger.logException(e);
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

public class Timerservice  extends BroadcastReceiver {
public static final int REQUEST_CODE = 12345;
Context mContext;
public static final String ACTION = "com.codepath.example.servicesdemo.alarm";

// Triggered by the Alarm periodically (starts the service to run task)
@Override
public void onReceive(Context context, Intent intent) {

  final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  if ( !manager.isProviderEnabled(LocationManager.GPS_PROVIDER) ) {
    Intent i1 = new Intent(context, AlertDialogActivity.class);
    i1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i1);
    //   buildAlertMessageNoGps();
  }else{
    Intent i = new Intent(context, GPSTracker.class);
    context.startService(i);
  }
}

}

代码示例来源:origin: Neamar/KISS

/**
 * Open an activity displaying details regarding the current package
 */
private void launchAppDetails(Context context, AppPojo app) {
  if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
    assert launcher != null;
    launcher.startAppDetailsActivity(className, appPojo.userHandle.getRealHandle(), null, null);
  } else {
    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
        Uri.fromParts("package", app.packageName, null));
    context.startActivity(intent);
  }
}

代码示例来源:origin: stackoverflow.com

/**
  * Display a dialog that user has no internet connection
  * @param ctx1
  *
  * Code from: http://osdir.com/ml/Android-Developers/2009-11/msg05044.html
  */
 public static void showNoConnectionDialog(Context ctx1) {
   final Context ctx = ctx1;
   AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
   builder.setCancelable(true);
   builder.setMessage(R.string.no_connection);
   builder.setTitle(R.string.no_connection_title);
   builder.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() {
     public void onClick(DialogInterface dialog, int which) {
       ctx.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
     }
   });
   builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
     public void onClick(DialogInterface dialog, int which) {
       return;
     }
   });
   builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
     public void onCancel(DialogInterface dialog) {
       return;
     }
   });
   builder.show();
 }

代码示例来源:origin: stackoverflow.com

public class Receiver extends ParsePushBroadcastReceiver {

  @Override
  public void onPushOpen(Context context, Intent intent) {
    Log.e("Push", "Clicked");
    Intent i = new Intent(context, HomeActivity.class);
    i.putExtras(intent.getExtras());
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
  }
}

代码示例来源:origin: ybq/Android-SpinKit

public static void start(Context context, int position) {
  Intent intent = new Intent(context, DetailActivity.class);
  intent.putExtra("position", position);
  context.startActivity(intent);
}

代码示例来源:origin: stackoverflow.com

locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);
  isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
  isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
alertDialog.setMessage(R.string.GPSAlertDialogMessage);
alertDialog.setPositiveButton(R.string.action_settings, new DialogInterface.OnClickListener() {
    mContext.startActivity(intent);

代码示例来源:origin: iMeiji/Toutiao

public static void launch(WendaContentBean.AnsListBean bean) {
  InitApp.AppContext.startActivity(new Intent(InitApp.AppContext, WendaDetailActivity.class)
      .putExtra(TAG, bean)
      .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}

代码示例来源:origin: stackoverflow.com

public class SafetyReceiver extends BroadcastReceiver {

  @Override
  public void onReceive(Context context, Intent intent) {
    ActivityManager as = (ActivityManager) context
        .getSystemService(Activity.ACTIVITY_SERVICE);
    if (IsNavigationRunning(as)) {
      Intent i = new Intent(context, VoiceActivity.class);
      i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      context.startActivity(i);
    }
  }
}

代码示例来源:origin: stackoverflow.com

public void onReceive(Context context, Intent intent) {
 Log.v(Tag, "Start Listening Phone Call");
 TelephonyManager tm = (TelephonyManager) context
     .getSystemService(Context.TELEPHONY_SERVICE);
 switch (tm.getCallState()) {
 case TelephonyManager.CALL_STATE_IDLE:
   Log.v(Tag, "No call");
   break;
 case TelephonyManager.CALL_STATE_RINGING:
   Log.v(Tag, "A new call arrived and is ringing or waiting");
   Intent i = new Intent(context,MyActivity.class);
   i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   context.startActivity(i);
   break;
 }

相关文章

Context类方法