Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime picker FragmentManager exception

I've integrated the following library from GitHub into my project:

https://github.com/jjobes/SlideDateTimePicker

It has been integrated fine but does not work when executed.
I have created the following FragmetActivity which simply has a button that launches the library. When the button is clicked, it crashes. The Activity is set to have a Dialog Theme.

<activity
            android:name=".AlertDateTimePickerParentActivity"
            android:screenOrientation="landscape"
            android:theme="@style/Theme.AppCompat.Dialog"
            android:excludeFromRecents="true"/>

FragmetActivity:

/**
 * Created by MatthewW on 27/04/2018.
 */

import java.text.SimpleDateFormat;
import java.util.Date;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.github.jjobes.slidedatetimepicker.SlideDateTimeListener;
import com.github.jjobes.slidedatetimepicker.SlideDateTimePicker;


public class AlertDateTimePickerParentActivity extends FragmentActivity{


    private static final String TAG = AlertDateTimePickerParentActivity.class.getSimpleName();
    private SimpleDateFormat mFormatter = new SimpleDateFormat("MMMM dd yyyy hh:mm aa");
    private Button mButtonSetStartDate;



    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.alerdtparentactivitylayout);
        this.setFinishOnTouchOutside(false); //stops this activity being destroyed if user clicks outside the activity window

        mButtonSetStartDate = (Button) findViewById(R.id.mButtonSetStartDate);

        mButtonSetStartDate.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v)
            {
                new SlideDateTimePicker.Builder(getSupportFragmentManager())
                        .setListener(listener)
                        .setInitialDate(new Date())
                        //.setMinDate(minDate)
                        //.setMaxDate(maxDate)
                        //.setIs24HourTime(true)
                        //.setTheme(SlideDateTimePicker.HOLO_DARK)
                        //.setIndicatorColor(Color.parseColor("#990000"))
                        .build()
                        .show();
            }
        });


    }//end of onCreate



    private SlideDateTimeListener listener = new SlideDateTimeListener() {

        @Override
        public void onDateTimeSet(Date date)
        {
            Toast.makeText(AlertDateTimePickerParentActivity.this,
                    mFormatter.format(date), Toast.LENGTH_SHORT).show();
        }

        // Optional cancel listener
        @Override
        public void onDateTimeCancel()
        {
            Toast.makeText(AlertDateTimePickerParentActivity.this,
                    "Canceled", Toast.LENGTH_SHORT).show();
        }
    };


}//end of class

The exception:

 Process: com.carefreegroup.rr3.carefreeoncall, PID: 22908
java.lang.IllegalStateException: Fragment DateFragment{427539b8 #0 id=0x7f0b0259 android:switcher:2131427929:0} declared target fragment SlideDateTimeDialogFragment{4273f670 #0 tagSlideDateTimeDialogFragment} that does not belong to this FragmentManager!
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1266)
    at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1574)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1641)
    at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:794)
    at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2415)
    at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2200)
    at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2153)
    at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2034)
    at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:651)
    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
    at android.support.v4.view.ViewPager.populate(ViewPager.java:1239)
    at android.support.v4.view.ViewPager.populate(ViewPager.java:1087)
    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1613)
    at com.github.jjobes.slidedatetimepicker.CustomViewPager.onMeasure(CustomViewPager.java:70)
    at android.view.View.measure(View.java:17275)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
    at android.view.View.measure(View.java:17275)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.view.View.measure(View.java:17275)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.view.View.measure(View.java:17275)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5352)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2541)
    at android.view.View.measure(View.java:17275)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2208)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1325)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1547)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1226)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6362)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
    at android.view.Choreographer.doCallbacks(Choreographer.java:603)
    at android.view.Choreographer.doFrame(Choreographer.java:573)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5350)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
    at dalvik.system.NativeStart.main(Native Method)

I've tried looking around the net for answers and some point to the problem being the fragment being displayed(DateTime picker), does not belong to the Fragment manager of the enclosing FragmentActivity. I'm not sure exactly what this means.

Has anyone any ideas what could be wrong here?

I'm running this on a Samsung Galaxy tablet SM-T520 with Android 4.4.2

. manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.rr3.carefreeoncall"
    android:versionCode="44"
    android:versionName="2.3.2" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="22" />

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.GET_TASKS" /> 
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>  

    <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />

    <application
        android:name=".RROnCallApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/CustomActionBarTheme">


    <activity 
      android:name="com.carefreegroup.rr3.carefreeoncall.OnCallMenuActivity"
            android:label="@string/app_name"
            android:screenOrientation="landscape">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <activity
            android:name=".OnCallListAndDetailsActivity"
            android:screenOrientation="landscape" />

        <activity
            android:name=".DisplayCarerDetailsfragmentActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".PurposeOfCallActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".UpdateCallActivity"
            android:screenOrientation="landscape" />

        <activity
            android:name=".UpdateCallDateTimeAndCarerActivity"
            android:screenOrientation="landscape" />

        <activity
            android:name=".UpdateCallDateTimeActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".UpdateCallNewCarerListActivity"
            android:screenOrientation="portrait" />


        <activity
            android:name=".DisplayCarerInfofragmentActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".MenuActivity"
            android:screenOrientation="landscape" />

        <activity
            android:name=".MenuActivity2"
            android:screenOrientation="landscape" />

        <activity
            android:name=".client.DisplayClientDetailsfragmentActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.DisplayClientInfofragmentActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.ClientListDetailsPurposeActivity"
            android:screenOrientation="landscape" />


        <activity
            android:name=".CarerAwayActivity"
            android:screenOrientation="landscape" />

        <activity
            android:name=".DisplayCarerAwayDateTimeFragmentActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".DisplayAwayReasonActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.DisplayClientAwayDateTimeFragmentActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.DisplayClientAwayReasonActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.ClientAwayActivity"
            android:screenOrientation="landscape" />

         <activity
            android:name=".client.UpdateCallDateTimeAndClientActivity"
            android:screenOrientation="landscape" />

        <activity
            android:name=".client.UpdateCallDateTimeClientActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.UpdateCallNewCarerListActivityClient"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.PurposeOfCallActivityClient"
            android:screenOrientation="portrait" />

        <activity
            android:name=".CarerSendLogActivity"
            android:screenOrientation="landscape" />

        <activity
            android:name=".CarerViewLogActivity"
            android:screenOrientation="landscape" />



        <activity
            android:name=".client.ClientSendLogActivity"
            android:screenOrientation="landscape" />

        <activity
            android:name=".CancelCallActivity"
            android:screenOrientation="landscape" />


        <activity
            android:name=".CancelCallActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.CancelCallActivityClient"
            android:screenOrientation="landscape" />

        <activity
            android:name=".client.CancelCallActivityPhoneClient"
            android:screenOrientation="portrait" />

        <activity
            android:name=".ShowUnallocatedCallsActivity"
            android:screenOrientation="landscape" />

        <activity
            android:name=".PurposeOfCallActivityUnalloc"
            android:screenOrientation="portrait" />

        <activity
            android:name=".ShowUnallocatedCallsActivityPhone"
            android:screenOrientation="portrait" />


        <activity
            android:name=".ShowMissedCallsActivity"
            android:screenOrientation="landscape" />

        <activity
            android:name=".ShowMissedCallsActivityPhone"
            android:screenOrientation="portrait" />


        <activity
            android:name=".PurposeOfCallActivityMissed"
            android:screenOrientation="portrait" />


        <activity
            android:name=".ShowAlertsActivity"
            android:screenOrientation="landscape"
            android:launchMode="singleInstance" />

        <activity
            android:name=".AlertDetailsActivityPhone"
            android:screenOrientation="portrait" />



        <activity
            android:name=".GetRotaDetails2"
            android:screenOrientation="landscape" />

        <activity
            android:name=".GetRotaDetailsForPhone"
            android:screenOrientation="portrait" />




        <service android:name=".GetCarerService"></service>
        <service android:name=".GetCarersIntentService"></service>
        <service android:name=".client.GetClientsIntentService"></service>
        <service android:name=".SendcarerMessageIntentService"></service>
        <service android:name=".SendcarerMessageSMSIntentService"></service>
        <service android:name=".ShowAlertsIntentService"></service>

        <receiver
            android:name="AlarmReceiver" >
        </receiver>

        <activity
            android:name=".TreeViewListDemo"
            android:screenOrientation="landscape" />





        <activity
            android:name=".ExpList"
            android:screenOrientation="landscape" />

        <activity
            android:name=".RunsDetailsPurposeActivity"
            android:screenOrientation="landscape" />

        <activity
            android:name=".DisplayRunDetailsfragmentActivity"
            android:screenOrientation="portrait" />

         <activity
            android:name=".RunPurposeOfCallActivity"
            android:screenOrientation="portrait" />

        <activity
            android:name=".CarerAwayListFragmentActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".CarerAwayDateUpdateActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".CarerAwayReasonActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".CarerAwayReasonUpdateActivityPhone"
            android:screenOrientation="portrait" />



        <activity
            android:name=".client.ClientAwayListFragmentActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.ClientAwayReasonActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.ClientAwayDateUpdateActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.AddCallActivity"
             />

        <activity
            android:name=".client.AddCallDateTimeActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.AddCallContractsActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.AddCallRunsActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".client.AddCallCarerActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".CarerViewLogActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".CarerViewLogsListFragmentActivityPhone"
            android:screenOrientation="portrait" />

        <activity
            android:name=".ShowInboxSentboxActivity"
            android:screenOrientation="landscape" />

         <activity
            android:name=".InboxFragmentActivityPhone"
            android:screenOrientation="portrait" />


         <activity
            android:name=".HelpActivity"
            android:screenOrientation="landscape" />

         <activity
            android:name=".UpdateMultiCallWithRunAndCarerActivity"
            android:screenOrientation="landscape" />


         <activity
            android:name=".UpdateMultiCallWithRunActivityPhone"
            android:screenOrientation="portrait" />

         <activity
            android:name=".UpdateMultiCallWithCarerActivityPhone"
            android:screenOrientation="portrait" />

         <activity
            android:name=".UpdateSingleCallWithRunActivityPhone"
            android:screenOrientation="portrait" />

        <service android:name=".MailService"></service>

        <activity
            android:name=".SendGroupMessageActivity"
            android:screenOrientation="landscape" />

        <service android:name=".SendCarerGroupMessageService"></service>

        <activity
            android:name=".AlertDateTimePickerParentActivity"
            android:screenOrientation="landscape"
            android:excludeFromRecents="true"/>


    </application>

</manifest>
like image 948
turtleboy Avatar asked Apr 27 '18 14:04

turtleboy


Video Answer


1 Answers

Make sure you're using only one type of FragmentManager either getFragmentManager() from android.app.fragment or getSupportFragmentManager() from android.support.v4.fragment. I also encountered this error, & the reason was this. I extended both from support library, but somehow, I was initiating one from app library, & calling other from support. Give it a try

like image 112
Ganesh Avatar answered Sep 30 '22 15:09

Ganesh