Mar*_*rio 2 android android-intent
我目前正在开发一款在googleMaps视图中使用GPS定位的应用.我检查GPS功能是否被激活,如果没有,我将用户重定向到设置菜单.
这是我的代码的罪名部分:
Button btnLocateMe = (Button)findViewById(Rsendlocationinfo.id.locateme);
btnLocateMe.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Context context = getApplicationContext();
objgps = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
//Check GPS configuration
if ( !objgps.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
//Warn the user that its GPS is not activated
Toast gpsActivationCheck = Toast.makeText(context, "GPS deactivated - Touch to open the GPS settings.", Toast.LENGTH_LONG);
gpsActivationCheck.show();
//Open the GPS settings menu on the next onTouch event
//by implementing directly the listener method - dirt manner
mapView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
//And here is my problem - How to kill this process
startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
return false;
}
});
}
else {
//Location acquisition.
}
Run Code Online (Sandbox Code Playgroud)
我尝试了一些stopself(),finish(),在onStop(),onDestroy(),onPause()......它崩溃或什么都不做......你能帮我一把吗?
好的,我终于找到了.
我将尝试清楚地解释行为的差异:
旧行为:
启动此意图的代码是:
startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
Run Code Online (Sandbox Code Playgroud)
新行为:
我的代码现在是:
Intent intentRedirectionGPSSettings = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
intentRedirectionGPSSettings.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivityForResult(intentRedirectionGPSSettings, 0);
Run Code Online (Sandbox Code Playgroud)
我试着解释清楚.manifest.xml中的标签"android:noHistory(true)"适用于活动,但标志FLAG_ACTIVITY_NO_HISTORY是一个很好的选择,因为它适用于意图.
谢谢你的帮助.
| 归档时间: |
|
| 查看次数: |
4262 次 |
| 最近记录: |