forked from organicmaps/organicmaps
[android] fix “Can not perform this action after onSaveInstanceState” exception
This commit is contained in:
parent
51410622d9
commit
382550e40b
12 changed files with 56 additions and 20 deletions
|
@ -83,7 +83,6 @@
|
|||
|
||||
<activity
|
||||
android:name="com.mapswithme.maps.SplashActivity"
|
||||
android:configChanges="orientation|screenLayout|screenSize"
|
||||
android:label="@string/app_name">
|
||||
|
||||
<intent-filter>
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv__logo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/img_logo"/>
|
||||
|
|
|
@ -450,6 +450,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
protected void safeOnCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.safeOnCreate(savedInstanceState);
|
||||
if (savedInstanceState != null)
|
||||
mLocationErrorDialogAnnoying = savedInstanceState.getBoolean(EXTRA_LOCATION_DIALOG_IS_ANNOYING);
|
||||
mIsFragmentContainer = getResources().getBoolean(R.bool.tabletLayout);
|
||||
|
|
|
@ -57,6 +57,7 @@ public class MwmApplication extends Application
|
|||
private AppBackgroundTracker mBackgroundTracker;
|
||||
|
||||
private boolean mIsFrameworkInitialized;
|
||||
private boolean mIsPlatformInitialized;
|
||||
|
||||
private Handler mMainLoopHandler;
|
||||
private final Object mMainQueueToken = new Object();
|
||||
|
@ -155,6 +156,9 @@ public class MwmApplication extends Application
|
|||
|
||||
public void initNativePlatform()
|
||||
{
|
||||
if (mIsPlatformInitialized)
|
||||
return;
|
||||
|
||||
final boolean isInstallationIdFound = setInstallationIdToCrashlytics();
|
||||
|
||||
initTracker();
|
||||
|
@ -180,6 +184,7 @@ public class MwmApplication extends Application
|
|||
mBackgroundTracker.addListener(mBackgroundListener);
|
||||
TrackRecorder.init();
|
||||
Editor.init();
|
||||
mIsPlatformInitialized = true;
|
||||
}
|
||||
|
||||
public void initNativeCore()
|
||||
|
@ -256,6 +261,10 @@ public class MwmApplication extends Application
|
|||
{
|
||||
return mIsFrameworkInitialized;
|
||||
}
|
||||
public boolean isPlatformInitialized()
|
||||
{
|
||||
return mIsPlatformInitialized;
|
||||
}
|
||||
|
||||
public String getApkPath()
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapswithme.maps.ads.LikesManager;
|
||||
import com.mapswithme.maps.editor.ViralFragment;
|
||||
|
@ -45,6 +46,8 @@ public class SplashActivity extends AppCompatActivity
|
|||
// The first launch of application ever - onboarding screen will be shown.
|
||||
private static boolean sFirstStart;
|
||||
|
||||
private View mIvLogo;
|
||||
|
||||
private boolean mPermissionsGranted;
|
||||
|
||||
public static void start(@NonNull Context context,
|
||||
|
@ -101,25 +104,30 @@ public class SplashActivity extends AppCompatActivity
|
|||
|
||||
sFirstStart = FirstStartFragment.showOn(this, this);
|
||||
if (sFirstStart)
|
||||
{
|
||||
UiUtils.hide(mIvLogo);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NewsFragment.showOn(this, this))
|
||||
boolean showNews = NewsFragment.showOn(this, this);
|
||||
if (!showNews)
|
||||
{
|
||||
if (ViralFragment.shouldDisplay())
|
||||
{
|
||||
UiUtils.hide(mIvLogo);
|
||||
ViralFragment dialog = new ViralFragment();
|
||||
dialog.onDismiss(new DialogInterface()
|
||||
{
|
||||
@Override
|
||||
public void cancel()
|
||||
{
|
||||
processNavigation();
|
||||
onDialogDone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss()
|
||||
{
|
||||
processNavigation();
|
||||
onDialogDone();
|
||||
}
|
||||
});
|
||||
dialog.show(getSupportFragmentManager(), "");
|
||||
|
@ -130,6 +138,10 @@ public class SplashActivity extends AppCompatActivity
|
|||
processNavigation();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UiUtils.hide(mIvLogo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,7 +153,7 @@ public class SplashActivity extends AppCompatActivity
|
|||
return;
|
||||
|
||||
boolean isWriteGranted = false;
|
||||
for (int i = 0; i < permissions.length; ++i)
|
||||
for (int i = 0; i < permissions.length; i++)
|
||||
{
|
||||
int result = grantResults[i];
|
||||
String permission = permissions[i];
|
||||
|
@ -171,6 +183,7 @@ public class SplashActivity extends AppCompatActivity
|
|||
{
|
||||
UiUtils.setupStatusBar(this);
|
||||
setContentView(R.layout.activity_splash);
|
||||
mIvLogo = findViewById(R.id.iv__logo);
|
||||
}
|
||||
|
||||
private void init()
|
||||
|
|
|
@ -18,7 +18,8 @@ public class ConnectivityChangedReceiver extends BroadcastReceiver
|
|||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
if (!MwmApplication.get().isFrameworkInitialized() || !ConnectionState.isWifiConnected()
|
||||
MwmApplication.get().initNativePlatform();
|
||||
if (!ConnectionState.isWifiConnected()
|
||||
|| MapManager.nativeNeedMigrate())
|
||||
return;
|
||||
|
||||
|
|
|
@ -125,10 +125,22 @@ public class WorkerService extends IntentService
|
|||
private static boolean processLocation()
|
||||
{
|
||||
final LocationManager manager = (LocationManager) MwmApplication.get().getSystemService(Context.LOCATION_SERVICE);
|
||||
final Location l = manager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
|
||||
Location l = null;
|
||||
try
|
||||
{
|
||||
l = manager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
|
||||
}
|
||||
catch (SecurityException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (l == null || LocationUtils.isExpired(l, l.getTime(), LocationUtils.LOCATION_EXPIRATION_TIME_MILLIS_LONG))
|
||||
return false;
|
||||
|
||||
MwmApplication.get().initNativePlatform();
|
||||
MwmApplication.get().initNativeCore();
|
||||
|
||||
String country = MapManager.nativeFindCountry(l.getLatitude(), l.getLongitude());
|
||||
if (TextUtils.isEmpty(country))
|
||||
return false;
|
||||
|
|
|
@ -13,7 +13,7 @@ public class BaseMwmFragment extends Fragment
|
|||
public void onAttach(Context context)
|
||||
{
|
||||
super.onAttach(context);
|
||||
if (context instanceof AppCompatActivity && !MwmApplication.get().isFrameworkInitialized())
|
||||
if (context instanceof AppCompatActivity && !MwmApplication.get().isPlatformInitialized())
|
||||
{
|
||||
((AppCompatActivity)context).getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
|
|
|
@ -55,7 +55,7 @@ public class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
mSavedState = savedInstanceState;
|
||||
if (!MwmApplication.get().isFrameworkInitialized()
|
||||
if (!MwmApplication.get().isPlatformInitialized()
|
||||
|| !Utils.checkPermissions(this, SplashActivity.PERMISSIONS))
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -67,6 +67,12 @@ public class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
mBaseDelegate.onCreate();
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
safeOnCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
protected void safeOnCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
final int layoutId = getContentLayoutResId();
|
||||
if (layoutId != 0)
|
||||
|
@ -85,12 +91,6 @@ public class BaseMwmFragmentActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
attachDefaultFragment();
|
||||
|
||||
safeOnCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
protected void safeOnCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
}
|
||||
|
||||
protected boolean isInitializationComplete()
|
||||
|
|
|
@ -22,7 +22,7 @@ public abstract class BaseMwmListFragment extends ListFragment
|
|||
public void onAttach(Context context)
|
||||
{
|
||||
super.onAttach(context);
|
||||
if (context instanceof AppCompatActivity && !MwmApplication.get().isFrameworkInitialized())
|
||||
if (context instanceof AppCompatActivity && !MwmApplication.get().isPlatformInitialized())
|
||||
{
|
||||
((AppCompatActivity)context).getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
|
|
|
@ -45,7 +45,7 @@ public abstract class BaseMwmRecyclerFragment extends Fragment
|
|||
public void onAttach(Context context)
|
||||
{
|
||||
super.onAttach(context);
|
||||
if (context instanceof AppCompatActivity && !MwmApplication.get().isFrameworkInitialized())
|
||||
if (context instanceof AppCompatActivity && !MwmApplication.get().isPlatformInitialized())
|
||||
{
|
||||
((AppCompatActivity)context).getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
|
|
|
@ -308,9 +308,9 @@ public abstract class BaseNewsFragment extends BaseMwmDialogFragment
|
|||
final BaseNewsFragment fragment = clazz.newInstance();
|
||||
fragment.mListener = listener;
|
||||
activity.getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(fragment, clazz.getName())
|
||||
.commitAllowingStateLoss();
|
||||
.beginTransaction()
|
||||
.add(fragment, clazz.getName())
|
||||
.commitAllowingStateLoss();
|
||||
} catch (java.lang.InstantiationException ignored)
|
||||
{}
|
||||
catch (IllegalAccessException ignored)
|
||||
|
|
Loading…
Add table
Reference in a new issue