开始活动而不在屏幕上闪烁/闪烁

时间:2020-09-04 10:15:46

标签: android

我创建了一个应用程序,用于检查设备是否已连接到特定的WiFi SSID,如果已连接,则它将设备的位置发送到服务器。效果很好。

我使用JobScheduler定期启动此应用/活动,以使用以下示例获取发送的位置:https://www.vogella.com/tutorials/AndroidTaskScheduling/article.html

我的问题是,无论我尝试什么,从OnStartJob启动该应用程序时,它在屏幕上都会闪烁。如何定期启动它以使用户看不见?

我当前的代码是:

 public boolean onStartJob(JobParameters params) {
            Intent intent = new Intent(this, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            startActivity(intent);
.
.
}

我有android:theme="@android:style/Theme.NoDisplay"

在onCreate结束时我有

finish();
overridePendingTransition(0, 0);

MainActivity包含具有以下方法的LocationListener:

public void onProviderDisabled(String provider) {
                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                startActivity(intent);
               // overridePendingTransition(0, 0);
}

1 个答案:

答案 0 :(得分:0)

如果您想重新开始活动,请使用此代码

 finish();
 overridePendingTransition(0, 0);
 startActivity(getIntent());
 overridePendingTransition(0, 0);

如果您想参加其他活动,请使用此代码

        Intent intent = new Intent(this,SecontActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(intent);