我在我的 android 应用上启用了深度链接,它运行良好。但是,我希望意图过滤器仅侦听特定的 pathPrefix,即 http(s)://(www.)mydomain.com/e 而不是任何其他 pathPrefix。这可能吗?我在 AndroidManifest.xml 中附加了我的意图过滤器代码
<intent-filter android:label="My App Name">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="www.domain.com"
android:pathPrefix="/e" />
<data android:scheme="http"
android:host="mydomain.com"
android:pathPrefix="/e" />
<data android:scheme="https"
android:host="www.mydomain.com"
android:pathPrefix="/e" />
<data android:scheme="https"
android:host="mydomain.com"
android:pathPrefix="/e" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud) 我在类的主线程上保留了一个打开的领域实例Application,并使用该单个实例从MainActivity. 由于我的应用程序有一个活动,因此我关闭了该活动的onDestroy(). 到目前为止,该应用程序对我来说运行良好。
不做会有什么后果realm.close()?无论有没有相同的情况,我的数据库都没有损坏。
另外,我读到在某些情况下活动onDestroy()可能根本不会被调用。如果关闭领域如此重要,数据库在这种情况下会产生什么影响?
public class MyApp extends Application {
private static MyApp instance;
private Realm realm;
public void onCreate() {
super.onCreate();
Realm.init(this);
Realm.setDefaultConfiguration(new RealmConfiguration.Builder()
.schemaVersion(BuildConfig.VERSION_CODE)
.migration(new RealmMigrationClass())
.compactOnLaunch()
.build());
realm = Realm.getInstance(Realm.getDefaultConfiguration());
}
public static MyApp getInstance() {
return instance;
}
public Realm getRealm() {
return realm;
}
}
Run Code Online (Sandbox Code Playgroud)
主要活动
public class MainActivity extends Activity {
@Override
protected void onDestroy() {
MyApp.getInstance().getRealm().close();
super.onDestroy();
}
}
Run Code Online (Sandbox Code Playgroud) 我编写了我的自定义位置管理器,每 30 秒检查一次用户位置的更新。代码运行良好,即我正在接收用户所在位置的更新。但问题是 GPS 图标始终在顶部的状态栏上可见。我猜它应该在 30 秒内只可见一次。这是正常的还是我做错了什么?

public volatile Double mLatitude = 0.0;
public volatile Double mLongitude = 0.0;
int minTime = 30000;
float minDistance = 0;
MyLocationListener myLocListener = new MyLocationListener();
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setSpeedRequired(false);
String bestProvider = locationManager.getBestProvider(criteria, false);
locationManager.requestSingleUpdate(criteria, myLocListener, null);
locationManager.requestLocationUpdates(bestProvider, minTime, minDistance, myLocListener);
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc)
{
if (loc != null) {
//Do something knowing the location …Run Code Online (Sandbox Code Playgroud) 为了使我的问题可以理解,我使用以下示例代码.这段代码的输出是5,而我希望它是3.我猜测B是作为A的指针,但是我希望A最初在B中复制,而A中的后续更改不应该影响B .
import java.io.*;
public class fg
{
public static void main(String args[]) throws Exception
{
int[] A = new int[3];
A[0]=1;
A[1]=3;
A[3]=7;
check(A);
}
public static void check(int[] A)
{
int[] B = A;
A[1] = 5;
System.out.println(B[1]);
}
Run Code Online (Sandbox Code Playgroud)
}