Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Multiple maps cause Fragment crash #480

Open
m1ga opened this issue Sep 13, 2021 · 0 comments
Open

Android: Multiple maps cause Fragment crash #480

m1ga opened this issue Sep 13, 2021 · 0 comments

Comments

@m1ga
Copy link
Contributor

m1ga commented Sep 13, 2021

When adding two maps into one window or view that app will crash:

const Map = require("ti.map");
var win = Titanium.UI.createWindow({
	layout: "vertical"
});
win.add(Map.createView({
	mapType: Map.NORMAL_TYPE,
	region: {
		latitude: 37.74,
		longitude: -122.41,
		latitudeDelta: 0.01,
		longitudeDelta: 0.01
	},
	animate: false,
	regionFit: true,
	userLocation: true,
	height: 250,
	width: Ti.UI.FILL,
}));

win.add(Map.createView({
	mapType: Map.NORMAL_TYPE,
	region: {
		latitude: 37.74,
		longitude: -122.41,
		latitudeDelta: 0.01,
		longitudeDelta: 0.01
	},
	animate: false,
	regionFit: true,
	userLocation: false,
	height: 250,
	width: Ti.UI.FILL
}))
win.open();

crash:

[ERROR] TiExceptionHandler: (main) [249,550] android.widget.ImageView cannot be cast to android.view.ViewGroup
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler:     androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:504)
[ERROR] TiExceptionHandler:     androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
[ERROR] TiExceptionHandler:     androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
[ERROR] TiExceptionHandler:     androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
[ERROR] TiExceptionHandler:     androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
[ERROR] TiExceptionHandler:     androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:3138)
[ERROR] TiExceptionHandler:     androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:3072)
[ERROR] TiExceptionHandler:     androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:251)
[ERROR] TiExceptionHandler:     androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:502)
[ERROR] TiExceptionHandler:     androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:246)
[ERROR] TiExceptionHandler:     org.appcelerator.titanium.TiBaseActivity.onStart(TiBaseActivity.java:1441)
[ERROR] TiExceptionHandler:     android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1435)
[ERROR] TiExceptionHandler:     android.app.Activity.performStart(Activity.java:8018)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.handleStartActivity(ActivityThread.java:3457)
[ERROR] TiExceptionHandler:     android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
[ERROR] TiExceptionHandler:     android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
[ERROR] TiExceptionHandler:     android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
[ERROR] TiExceptionHandler:     android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
[ERROR] TiExceptionHandler:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
[ERROR] TiExceptionHandler:     android.os.Handler.dispatchMessage(Handler.java:106)
[ERROR] TiExceptionHandler:     android.os.Looper.loop(Looper.java:223)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.main(ActivityThread.java:7664)
[ERROR] TiExceptionHandler:     java.lang.reflect.Method.invoke(Native Method)
[ERROR] TiExceptionHandler:     com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Ru

According to various sources like https://stackoverflow.com/a/39441496/5193915 it seems like a clash between IDs. If I had a new class as described here https://stackoverflow.com/a/16329503/5193915

CustomMapFragment.java

package ti.map;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.maps.GoogleMapOptions;
import com.google.android.gms.maps.SupportMapFragment;

public class CustomMapFragment extends SupportMapFragment {

    public CustomMapFragment() {
        super();
    }


    public static CustomMapFragment newInstance() {
        CustomMapFragment frag = new CustomMapFragment();
        return frag;
    }

    public static CustomMapFragment newInstance(GoogleMapOptions googleMapOptions){
        Bundle arguments = new Bundle();
        arguments.putParcelable("MapOptions", googleMapOptions);

        CustomMapFragment frag = new CustomMapFragment();
        frag.setArguments(arguments);
        return frag;
    }

    @Override
    public View onCreateView(LayoutInflater arg0, ViewGroup arg1, Bundle arg2) {
        View v = super.onCreateView(arg0, arg1, arg2);
        return v;
    }
}

and use that in https://github.com/appcelerator-modules/ti.map/blob/master/android/src/ti/map/TiUIMapView.java#L129 and https://github.com/appcelerator-modules/ti.map/blob/master/android/src/ti/map/TiUIMapView.java#L141

with Fragment map = CustomMapFragment.newInstance(); and Fragment map = CustomMapFragment.newInstance(gOptions); I can see both maps.

Since I'm not sure if that is causing other issues I didn't create a PR yet 😄 But the example code is running fine after that change.

@m1ga m1ga changed the title Android: Multiple maps cause Fragmet crash Android: Multiple maps cause Fragment crash Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant