在清单文件中,我添加了粗略和精细的权限,当我在使用Android 6的设备上运行时,没有任何反应!我尝试了一切,但无法获得位置更新......
我究竟做错了什么?
public class MainActivity extends AppCompatActivity implements LocationListener {
LocationManager locationManager;
String provider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
provider = locationManager.getBestProvider(new Criteria(), false);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. …
Run Code Online (Sandbox Code Playgroud) 当我使用InstantSearch Android时,会出现内存泄漏.
请参阅以下MainActivity
泄漏内存... hprof
显示它是一个问题com.algolia.instantsearch.ui.views.Hits
.什么人知道如何在被摧毁时摧毁那个视图Activity
?
public class MainActivity extends AppCompatActivity {
private Searcher searcher;
InstantSearch helper;
Hits hits;
LinearLayout activity_main;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
hits= (Hits) findViewById(R.id.hits);
activity_main= (LinearLayout) findViewById(R.id.activity_main);
searcher = Searcher.create("app_id","secret_key","Items");
helper = new InstantSearch(this, searcher);
helper.search();
}
@Override
protected void onDestroy() {
searcher=null;
helper=null;
hits.clear();
hits.removeAllViewsInLayout();
hits.removeAllViews();
hits.destroyDrawingCache();
hits.setBackground(null);
hits.setBackgroundResource(0);
hits=null;
activity_main.removeAllViewsInLayout();
activity_main.removeAllViews();
activity_main.destroyDrawingCache();
activity_main.setBackground(null);
activity_main.setBackgroundResource(0);
activity_main=null;
Log.i("AppInfo","Destroy");
super.onDestroy();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的activity_main.xml
:
<LinearLayout
android:id="@+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android" …
Run Code Online (Sandbox Code Playgroud)