- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我一直在尝试实现 android 的 MapView v2。除了这个错误,我让它工作得很好。
这是我从头开始加载应用程序时的样子...
如您所见,那里没有问题。
现在,当我按下“主页”按钮并尝试从“最近的应用程序”窗口访问该应用程序时,我得到以下信息:
它一直保持这种状态,直到我关闭该应用程序并从头开始重新加载它。
这是我的一些代码。
布局.xml
<LinearLayout
android:id="@+id/maps_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_marginBottom="100dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="100dip"/>
</LinearLayout>
Activity :
public class MyActivity extends BaseActivity {
private GoogleMap mMaps;
private LinearLayout mMapsContainer;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
mMapsContainer = (LinearLayout) findViewById(R.id.maps_container);
mMaps =((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onResume() {
super.onResume();
if (mMaps == null) {
mMaps = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
getSupportFragmentManager().findFragmentById(R.id.map).onResume();
}
基础 Activity :
public abstract class BaseActivity extends FragmentActivity implements
LocationListener,
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener {
// A request to connect to Location Services
private LocationRequest mLocationRequest;
// Stores the current instantiation of the location client in this object
private LocationClient mLocationClient;
// Handle to SharedPreferences for this app
SharedPreferences mPrefs;
// Handle to a SharedPreferences editor
SharedPreferences.Editor mEditor;
boolean mUpdatesRequested = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a new global location parameters object
mLocationRequest = LocationRequest.create();
mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);
// Use high accuracy
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
// Set the interval ceiling to one minute
mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);
// Note that location updates are off until the user turns them on
mUpdatesRequested = false;
// Open Shared Preferences
mPrefs = getSharedPreferences(LocationUtils.SHARED_PREFERENCES, Context.MODE_PRIVATE);
// Get an editor
mEditor = mPrefs.edit();
/*
* Create a new location client, using the enclosing class to
* handle callbacks.
*/
mLocationClient = new LocationClient(this, this, this);
}
@Override
public void onStop() {
// If the client is connected
if (mLocationClient.isConnected()) {
stopPeriodicUpdates();
}
// After disconnect() is called, the client is considered "dead".
mLocationClient.disconnect();
super.onStop();
}
@Override
public void onPause() {
// Save the current setting for updates
mEditor.putBoolean(LocationUtils.KEY_UPDATES_REQUESTED, mUpdatesRequested);
mEditor.commit();
super.onPause();
}
@Override
public void onStart() {
super.onStart();
/*
* Connect the client. Don't re-start any requests here;
* instead, wait for onResume()
*/
mLocationClient.connect();
}
@Override
public void onResume() {
super.onResume();
// If the app already has a setting for getting location updates, get it
if (mPrefs.contains(LocationUtils.KEY_UPDATES_REQUESTED)) {
mUpdatesRequested = mPrefs.getBoolean(LocationUtils.KEY_UPDATES_REQUESTED, false);
// Otherwise, turn off location updates until requested
} else {
mEditor.putBoolean(LocationUtils.KEY_UPDATES_REQUESTED, false);
mEditor.commit();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
// Choose what to do based on the request code
switch (requestCode) {
// If the request code matches the code sent in onConnectionFailed
case LocationUtils.CONNECTION_FAILURE_RESOLUTION_REQUEST :
switch (resultCode) {
// If Google Play services resolved the problem
case Activity.RESULT_OK:
break;
// If any other result was returned by Google Play services
default:
// Log the result
break;
}
// If any other request code was received
default:
// Report that this Activity received an unknown requestCode
Log.d(LocationUtils.APPTAG,
getString(R.string.unknown_activity_request_code, requestCode));
break;
}
}
private boolean servicesConnected() {
// Check that Google Play services is available
int resultCode =
GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
// If Google Play services is available
if (ConnectionResult.SUCCESS == resultCode) {
// In debug mode, log the status
Log.d(LocationUtils.APPTAG, getString(R.string.play_services_available));
// Continue
return true;
// Google Play services was not available for some reason
} else {
// Display an error dialog
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 0);
if (dialog != null) {
ErrorDialogFragment errorFragment = new ErrorDialogFragment();
errorFragment.setDialog(dialog);
// errorFragment.show(getSupportFragmentManager(), LocationUtils.APPTAG);
}
return false;
}
}
public void getAddress(View v) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && !Geocoder.isPresent()) {
// No geocoder is present. Issue an error message
Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_LONG).show();
return;
}
if (servicesConnected()) {
// Get the current location
Location currentLocation = mLocationClient.getLastLocation();
// Start the background task
(new GetAddressTask(this)).execute(currentLocation);
}
}
public void startUpdates(View v) {
mUpdatesRequested = true;
if (servicesConnected()) {
startPeriodicUpdates();
}
}
public void stopUpdates(View v) {
mUpdatesRequested = false;
if (servicesConnected()) {
stopPeriodicUpdates();
}
}
@Override
public void onConnected(Bundle bundle) {
if (mUpdatesRequested) {
startPeriodicUpdates();
}
EventBus.getDefault().post(new EventMessage().new LocationServicesConnected());
}
@Override
public void onDisconnected() {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
if (connectionResult.hasResolution()) {
try {
// Start an Activity that tries to resolve the error
connectionResult.startResolutionForResult(
this,
LocationUtils.CONNECTION_FAILURE_RESOLUTION_REQUEST);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
} else {
// If no resolution is available, display a dialog to the user with the error.
showErrorDialog(connectionResult.getErrorCode());
}
}
@Override
public void onLocationChanged(Location location) {
EventBus.getDefault().post(new EventMessage().new LocationChangedEvent(location));
}
private void startPeriodicUpdates() {
mLocationClient.requestLocationUpdates(mLocationRequest, this);
}
private void stopPeriodicUpdates() {
mLocationClient.removeLocationUpdates(this);
}
protected class GetAddressTask extends AsyncTask<Location, Void, String> {
// Store the context passed to the AsyncTask when the system instantiates it.
Context localContext;
// Constructor called by the system to instantiate the task
public GetAddressTask(Context context) {
// Required by the semantics of AsyncTask
super();
// Set a Context for the background task
localContext = context;
}
@Override
protected String doInBackground(Location... params) {
Geocoder geocoder = new Geocoder(localContext, Locale.getDefault());
// Get the current location from the input parameter list
Location location = params[0];
// Create a list to contain the result address
List<Address> addresses = null;
// Try to get an address for the current location. Catch IO or network problems.
try {
/*
* Call the synchronous getFromLocation() method with the latitude and
* longitude of the current location. Return at most 1 address.
*/
addresses = geocoder.getFromLocation(location.getLatitude(),
location.getLongitude(), 1
);
// Catch network or other I/O problems.
} catch (IOException exception1) {
// Log an error and return an error message
Log.e(LocationUtils.APPTAG, getString(R.string.IO_Exception_getFromLocation));
// print the stack trace
exception1.printStackTrace();
// Return an error message
return (getString(R.string.IO_Exception_getFromLocation));
// Catch incorrect latitude or longitude values
} catch (IllegalArgumentException exception2) {
// Construct a message containing the invalid arguments
String errorString = getString(
R.string.illegal_argument_exception,
location.getLatitude(),
location.getLongitude()
);
// Log the error and print the stack trace
Log.e(LocationUtils.APPTAG, errorString);
exception2.printStackTrace();
//
return errorString;
}
// If the reverse geocode returned an address
if (addresses != null && addresses.size() > 0) {
// Get the first address
Address address = addresses.get(0);
// Format the first line of address
String addressText = getString(R.string.address_output_string,
// If there's a street address, add it
address.getMaxAddressLineIndex() > 0 ?
address.getAddressLine(0) : "",
// Locality is usually a city
address.getLocality(),
// The country of the address
address.getCountryName()
);
// Return the text
return addressText;
// If there aren't any addresses, post a message
} else {
return getString(R.string.no_address_found);
}
}
/**
* A method that's called once doInBackground() completes. Set the text of the
* UI element that displays the address. This method runs on the UI thread.
*/
@Override
protected void onPostExecute(String address) {
}
}
/**
* Show a dialog returned by Google Play services for the
* connection error code
*
* @param errorCode An error code returned from onConnectionFailed
*/
private void showErrorDialog(int errorCode) {
// Get the error dialog from Google Play services
Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(
errorCode,
this,
LocationUtils.CONNECTION_FAILURE_RESOLUTION_REQUEST);
// If Google Play services can provide an error dialog
if (errorDialog != null) {
// Create a new DialogFragment in which to show the error dialog
ErrorDialogFragment errorFragment = new ErrorDialogFragment();
// Set the dialog in the DialogFragment
errorFragment.setDialog(errorDialog);
// Show the error dialog in the DialogFragment
// errorFragment.show(getSupportFragmentManager(), LocationUtils.APPTAG);
}
}
/**
* Define a DialogFragment to display the error dialog generated in
* showErrorDialog.
*/
public static class ErrorDialogFragment extends DialogFragment {
// Global field to contain the error dialog
private Dialog mDialog;
/**
* Default constructor. Sets the dialog field to null
*/
public ErrorDialogFragment() {
super();
mDialog = null;
}
/**
* Set the dialog to display
*
* @param dialog An error dialog
*/
public void setDialog(Dialog dialog) {
mDialog = dialog;
}
/*
* This method must return a Dialog to the DialogFragment.
*/
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return mDialog;
}
}
最佳答案
我在文件 manifest.xml 中禁用了硬件加速,我的应用程序在第二次加载时不再显示黑色 map 。我在模拟器中试了一下。
<application android:hardwareAccelerated="false">
...
</application
来自这篇文章:http://developer.android.com/guide/topics/graphics/hardware-accel.html
关于安卓 MapView v2 黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17603896/
我正在学习微处理器类(class),但我的代码有问题。 我需要编写一个程序代码,让一个词四处移动。 代码在 (80*25) 屏幕上正常工作(因为我的计算依赖于它) 但问题是:当我最大化显示屏幕时,一切
尝试使用 exoplayer v2.10.5 播放 m3u8 时变黑,这让我添加了或者我如何使用 exoplayer v2.10.5 和 gradle 3.5.3 播放 m3u 或者哪个版本的 exo
有几个现有的例子,但我想要一个使用 complex_filter 来实现目标的命令,而不需要做额外的事情,比如生成空白视频/音频文件。 环顾四周,这是迄今为止我想出的最好的: ffmpeg -i vi
服务是“允许服务与桌面交互”。 unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls,
我有一个显示youtube的本地ios应用程序,直到昨天该应用程序运行良好,但是现在该应用程序显示了youtube,只有当我触摸“播放”而不是播放视频时,它才显示黑屏。 我的应用程序没有更改,因此我认
我正在尝试向我的游戏添加一些基本的 HUD,但是当我尝试更改视角时,我可以看到文本(我之前提到过 HUD),但是在黑屏上。问题出在哪里? gl.glMatrixMode(GL_PROJ
我的转换不起作用,第一个 ImageView 显示了可绘制对象,但在运行动画时它只是以白屏结束。不确定我错过了什么。 主要布局 第二个 Activity 布局 主要 Activity pu
出于某种原因,当我尝试运行此代码时,我得到的只是黑屏。我怎样才能真正让它显示我想要显示的内容? 我正在使用 Eclipse,并且已将 lwjgl.jar 和 lwjgl_utils.jar 添加到构建
我正在遵循有关构建“弹出锁类型”游戏的教程,当我在模拟器中运行它时,会出现黑屏。我之前查过并尝试重置模拟器并重新启动计算机,但它不起作用有人可以帮助我并告诉我为什么会发生这种情况 import Spr
我正在尝试 MrSnakey 游戏。当我运行它时,它没有给我任何错误。但是,模拟器在启动时显示黑屏。你们不知道如何解决吗?解决此问题所需的有关我的项目的任何信息,请告诉我,我会在此处发布。 首先是 l
所以我遇到了相机卡住的问题。当它第一次被调用时,它工作得很好。并在按钮上显示我的图像。但是,如果我回到同一个按钮再次调用相机,或者调用相机的页面上的任何其他按钮,它会启动相机但不是黑屏。相机实际上并没
我几乎阅读了关于这个主题的所有帖子,但似乎没有一个有帮助。 我正在 try catch 当前屏幕的屏幕截图。为此,我正在使用 getDrawingCache。这是我的代码: mRootView.get
我已经用我命名为 Label 的类实现了 CCLabelProtocol 和 CRGBAProtocol: #import @interface Label : CCNode @property
晚上好。我为 iOS 开发了几年,自从 iOS8 发布以来,我遇到了一个奇怪的问题。我确信它会被修复,但现在是 8.1.2,而且它还在发生。在 iOS7 上一切正常,但在运行 iOS8 的手机上发生了
这是我的完整代码。当我右击几次(动画正常工作)时,屏幕卡住。我认为来自 if(SDL_GetTicks() - start_time format, 0, 0xFF, 0xFF ) );
我需要执行以下操作: 用户登录。 重定向至欢迎屏幕。 在加载大量记录时查看欢迎屏幕。 重定向到工作屏幕。 我正在寻找一种在 Action 类中执行类似操作的方法: public class LinkA
我在 KMZ 文件中有一个坐标数据集,我希望能够为用户提供使用 GMSPanoramaView(使用 1.6.0 版本的 Google-Maps-iOS-SDK)查看街景的选项).这是我的代码的样子:
在尝试将应用内 HTML 页面加载到我们的 UIWebView 时,我在 iOS9 上遇到了奇怪的行为 - 有时页面加载,有时只是显示为空白屏幕。 webViewDidFinishLoad 函数也在这
我试图显示我的收藏 View ,但我得到的只是黑屏。我知道我在某处遗漏了一些东西,但我似乎找不到它是什么。 #import "StoreCollectionViewController.h" #imp
我正在尝试从我们的 iOS 应用程序中删除所有 Storyboard,因为在使用 Git 的团队中工作时它们会变得一团糟。 我现在在 AppDelegate 的 application(_:didFi
我是一名优秀的程序员,十分优秀!