Android - mixed activity crashes, contains settings and periodically-updated text

0

this is quite a long post. I don't know very much about Android, but had to write an app. The app (handling a couple of intents and managing connectivity) runs smoothly and without problems. Now I have to add an UI.

I tried to create an activity containing both some settings (a numeric TextEditView and a Switch) and two text views (one containing a static text and one text updated periodically).

When I had only the textedit and the switch, everything worked flawlessly, but when I add the text view (even without the text updating functionality), the app crashes, giving some Reflections errors.

My first step was to add the TextViews to the layout file that defined the SettingsFragment. After that kept crashing, I tried to create two different fragments and add both to the SettingsActivity, which still keeps crashing.

Following the SettingsActivity tutorial on the Android dev pages, I got some messed up UI that sometimes launches before it crashes, and most of the time doesn't launch at all. All files contributing to the UI:

src/main/
     + java/<package>/
     |   + Info-Fragment.java    
     |   + SettingsFragment.java
     |   + SettingsActivity.java
     + res/
         + layout/
         |  + info_frag.xml
         |  + main.xml
         + xml/
         |  + pref_general.xml
         + ... all required strings and drawables

With pref_general defining the preferences fragment (which works, when on its own), info_frag defining the three TextViews, and main.xml describing a LinearLayout containing both fragments.

InfoFragment.java:

public class InfoFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        return inflater.inflate(R.layout.info_frag, container, false);
    }
}

SettingsFragment.java:

public class SettingsFragment extends PreferenceFragment {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.pref_general);
    }
}

SettingsActivity.java (create Activity, check state every 20 seconds, update text):

public class SettingsActivity
        extends PreferenceActivity {
    WatcherService ws = new WatcherService(); // an instance of the intent-watching service, provides methods that extract data from recorded intent sequences and saved application preferences; only created to access the timeLeft method (which can't be static)
    TextView tv = null;
    Handler hndlr = new Handler();

    Runnable timeChecker = new Runnable(){
        @Override
        public void run() {
            if (ws != null && tv != null) {
                long timeLeft = ws.loadMaximumTime() - ws.minutesOnline();
                tv.setText(Long.toString(timeLeft) + "min");
            }
            hndlr.postDelayed(this, 20*1000);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = (TextView) findViewById(R.id.rem_time);
        hndlr.post(timeChecker);
    }
}

Note that the crashes also occur when I don't create the Handler and Runnable, but simply try to set text to a fixed string.

And the layout files

pref_general.xml:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <SwitchPreference
        android:id="@+id/on_off_switch"
        android:defaultValue="true"
        android:key="active_switch"
        android:summary="description...."
        android:title="active?" />

    <EditTextPreference
        android:defaultValue="60"
        android:inputType="number"
        android:key="max_time"
        android:maxLines="1"
        android:selectAllOnFocus="true"
        android:singleLine="true"
        android:title="time"
        android:summary="the time"/>

</PreferenceScreen>

main.xml: (trying to display the info fragment and below that the pref fragment)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <fragment android:name="<PACKAGE NAME>.SettingsFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <fragment
        android:name="<PACKAGE NAME>.InfoFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

pref_fragment.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:gravity="center"
        android:text="@string/remaining"
        android:textSize="18sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/rem_time"
        android:gravity="center"
        android:textSize="25sp"
        android:text="60min"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <TextView
        android:text="@string/description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

Sometimes the info fragment will briefly show up, but it gets rendered over the settings fragment (or the other way around, can't distinguish that), so everything was an illegible mess.

I'm not into Android's UI complexity at all, so I might have misplanned everything completely. In this case I'd be glad for pointers to the right direction.

EDIT: Stacktrace on Huawai Honor 7

12-21 10:03:19.702 3216-3426/? I/logserver: handle_logfile_events, Object Path:/data/system/dropbox/, mask=0x00000080
12-21 10:03:19.702 3216-3426/? I/logserver: process_one_event, event->len=48, name=data_app_crash@1482310999701.txt
12-21 10:03:19.702 3216-3426/? I/logserver: find_first_match: find match, plogs(type=1, pfile=/data/system/dropbox/, match=app_crash)
12-21 10:03:19.702 3437-3437/? I/SendBroadcastPermission: action:android.intent.action.DROPBOX_ENTRY_ADDED, mPermissionType:0
12-21 10:03:19.706 3216-3426/? I/logserver: is_all_ready, any file is ready in non-keyfile exception.
12-21 10:03:19.707 3216-3426/? I/logserver: extract_appname, forward search, appname=de.waechtertroll.disciple
12-21 10:03:19.707 3216-3426/? I/logserver: archive_and_send, pos=0, type=crash, output=20161221100319_crash
12-21 10:03:19.707 3216-3426/? I/logserver: ---copy_match_files enter!!--
12-21 10:03:19.707 3216-3426/? I/logserver: [copy_match_files,864]: copy [/data/system/dropbox/data_app_crash@1482310999701.txt] to [/data/log/logcache/-147580624/data_app_crash@1482310999701.txt]
12-21 10:03:19.707 3216-3426/? I/logserver: get_fault_appname, appname=de.waechtertroll.disciple
12-21 10:03:19.707 3216-3426/? I/logserver: handle_archive_exception, BASIC_MODE
12-21 10:03:19.707 3216-3426/? I/logserver: remove_last_modify_file, into 1 times, file_dir:
12-21 10:03:19.707 3216-3426/? I/logserver: remove_last_modify_file, into 1 times, file_dir:
12-21 10:03:19.708 3216-3426/? I/logserver: get_disk_available_size, Disk_available = 3297972224 B = 3145 MB
12-21 10:03:19.708 3216-3426/? I/logserver: pack_files, output_path is /data/log/unzip.
12-21 10:03:19.708 3216-3426/? I/logserver: move_input_files, create dir [/data/log/unzip/PLK-L01_PLK-L01C432B371_0000000000_20161221100319_crash]
12-21 10:03:19.709 3216-3426/? I/logserver: handle_archive_exception, into set notify_type
12-21 10:03:19.710 3216-3426/? I/logserver: get_notify_mode, 1
12-21 10:03:19.710 3216-3426/? I/logserver: Process 3426 opened FIFO(10) for O_WRONLY
12-21 10:03:19.710 3216-3426/? I/logserver: notify_logcontrol, 3426 sent /data/log/unzip/PLK-L01_PLK-L01C432B371_0000000000_20161221100319_crash 
12-21 10:03:19.710 3216-3426/? I/logserver: check_dir_size, dir[/data/log/coredump/] doesn't exist
12-21 10:03:19.710 3216-3216/? I/logserver: process_event
12-21 10:03:19.710 3216-3426/? I/logserver: clean_cur_cache:999, system(rm -r /data/log/logcache/-147580624/* > /dev/null 2>&1)
12-21 10:03:19.710 3216-3216/? I/logserver: handle_fifo_msg, read res = 460, client pid = 3426, command = send log, data=/data/log/unzip/PLK-L01_PLK-L01C432B371_0000000000_20161221100319_crash
12-21 10:03:19.710 3216-3216/? I/logserver: handle_fifo_msg, 3426 sent /data/log/unzip/PLK-L01_PLK-L01C432B371_0000000000_20161221100319_crash 
12-21 10:03:19.710 3216-3425/? I/logserver: thread_logcontrol: /data/log/logcontrol has changed.
12-21 10:03:19.710 3216-3425/? I/logserver: handle_notify_event, send msg [submit:trigger=0,bugtype=2,modulename=de.waechtertroll.disciple,level=1,testtype=NORMAL,path=/data/log/unzip/PLK-L01_PLK-L01C432B371_0000000000_20161221100319_crash,mode=1;]
12-21 10:03:19.710 3216-3425/? I/logserver: send_to_client, send to (9) res = 172
12-21 10:03:19.753 4979-5029/? W/DeviceInfoFile: !devFile.exists()
12-21 10:03:19.759 4979-5029/? I/System.out: [chown, system.log, /log/LogService/3/done/Stabilization_PLK-L01_PLK-L01C432B371_HWlWDbSIL+DBYFl5ArsnFmlad89mU8mcWaiTK4Cj1+8=_20161221100319_crash_NORMAL.zip]
12-21 10:03:19.760 4979-5029/? I/System.out: null
12-21 10:03:19.760 4979-5029/? I/System.out: null
12-21 10:03:19.760 4979-5029/? I/System.out: Calling by::className:com.huawei.lcagent.util.FileUtils  MethodName:runCommand
12-21 10:03:19.785 4979-5029/? I/System.out: [chmod, 640, /log/LogService/3/done/Stabilization_PLK-L01_PLK-L01C432B371_HWlWDbSIL+DBYFl5ArsnFmlad89mU8mcWaiTK4Cj1+8=_20161221100319_crash_NORMAL.zip]
12-21 10:03:19.785 4979-5029/? I/System.out: null
12-21 10:03:19.785 4979-5029/? I/System.out: null
12-21 10:03:19.785 4979-5029/? I/System.out: Calling by::className:com.huawei.lcagent.util.FileUtils  MethodName:runCommand
12-21 10:03:19.811 4979-5029/? I/System.out: [chown, system.log, /log/LogService/3/uploading/Stabilization_PLK-L01_PLK-L01C432B371_HWlWDbSIL+DBYFl5ArsnFmlad89mU8mcWaiTK4Cj1+8=_20161221100319_crash_NORMAL.zip]
12-21 10:03:19.811 4979-5029/? I/System.out: null
12-21 10:03:19.811 4979-5029/? I/System.out: null
12-21 10:03:19.812 4979-5029/? I/System.out: Calling by::className:com.huawei.lcagent.util.FileUtils  MethodName:runCommand
12-21 10:03:19.837 4979-5029/? I/System.out: [chmod, 640, /log/LogService/3/uploading/Stabilization_PLK-L01_PLK-L01C432B371_HWlWDbSIL+DBYFl5ArsnFmlad89mU8mcWaiTK4Cj1+8=_20161221100319_crash_NORMAL.zip]
12-21 10:03:19.837 4979-5029/? I/System.out: null
12-21 10:03:19.837 4979-5029/? I/System.out: null
12-21 10:03:19.837 4979-5029/? I/System.out: Calling by::className:com.huawei.lcagent.util.FileUtils  MethodName:runCommand
12-21 10:03:19.871 4979-5028/? E/PackageLogInfoManager: checkPackageLogState, cr: android.app.ContextImpl$ApplicationContentResolver@bc5fd92, packageNames: null
12-21 10:03:20.024 3437-3453/? W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.huawei.lcagent.client.LogCollectManager.getUserType()' on a null object reference
12-21 10:03:20.024 3437-3453/? W/System.err:     at com.android.server.util.ReportTools.getUserType(ReportTools.java:86)
12-21 10:03:20.024 3437-3453/? W/System.err:     at com.android.server.util.ReportTools.isBetaUser(ReportTools.java:73)
12-21 10:03:20.024 3437-3453/? W/System.err:     at com.android.server.util.ReportTools.report(ReportTools.java:58)
12-21 10:03:20.024 3437-3453/? W/System.err:     at com.android.server.util.HwUserBehaviourRecord.appExitRecord(HwUserBehaviourRecord.java:65)
12-21 10:03:20.024 3437-3453/? W/System.err:     at com.android.server.am.ActivityManagerService$UiHandler.handleMessage(ActivityManagerService.java:1523)
12-21 10:03:20.024 3437-3453/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
12-21 10:03:20.024 3437-3453/? W/System.err:     at android.os.Looper.loop(Looper.java:150)
12-21 10:03:20.025 3437-3453/? W/System.err:     at android.os.HandlerThread.run(HandlerThread.java:61)
12-21 10:03:20.025 3437-3453/? W/System.err:     at com.android.server.ServiceThread.run(ServiceThread.java:46)
12-21 10:03:20.025 3437-3453/? E/ReportTools: This is not beta user build
12-21 10:03:20.031 20922-20922/de.waechtertroll.disciple I/Process: Sending signal. PID: 20922 SIG: 9
12-21 10:03:20.032 15286-15286/? I/HwSystemManager: DetectTask:destroy called!
12-21 10:03:20.032 15286-15286/? I/HwSystemManager: DetectTask:destroy called!
12-21 10:03:20.033 4441-13157/? I/PgedBinderListener: kstate callback type:8 value1=20922 value2=KILLED
12-21 10:03:20.042 15286-15286/? I/HwSystemManager: SimpleStateMachine:chage state from state:ScanEndState to state:QuiteState
12-21 10:03:20.101 3437-4341/? I/AccountManagerService: getTypesVisibleToCaller: isPermitted? true
12-21 10:03:20.117 3437-3901/? E/HsmCoreServiceImpl: onTransact in code is: 102
12-21 10:03:20.117 3437-3901/? I/MediaProcessHandler: processOp opType: 1, uid: 10149, pid: 20922
12-21 10:03:20.117 3437-3901/? W/MediaProcessHandler: remove target not exist, maybe the UI process: uid: 10149, pid: 20922
12-21 10:03:20.126 4441-5198/? W/PGApi_client: recv actoionId = 10010, action = com.huawei.pgmng.PGAction@b331c66 actionId =10010 pkg =com.huawei.android.launcher extend1 =2537 extend2 = flag =3 type =1
12-21 10:03:20.126 4441-5198/? W/PGMiddleWare: in handleAction method, action = 10010
12-21 10:03:20.126 4441-5198/? W/PGMiddleWare: in handleAction, invoke client = com.huawei.pgmng.middleware.AudioEffectLowPowerImpl@c439b5, action = com.huawei.pgmng.PGAction@b331c66 actionId =10010 pkg =com.huawei.android.launcher extend1 =2537 extend2 = flag =3 type =1
12-21 10:03:20.145 4206-4488/? I/HwSystemManager: NotificationGuideService:handle MSG_ACTIVIY_FOREGROUND, uid:10057
12-21 10:03:20.145 4470-4470/? I/HwLauncher: Launcher onStart()
12-21 10:03:20.145 4470-4470/? I/HwLauncher: Launcher dynamicIconsRegister
12-21 10:03:20.145 4470-4470/? I/HwLauncher: DynamicUpdater registerReceiver
12-21 10:03:20.147 4470-4470/? I/HwLauncher: DynamicUpdater call updateFolder
12-21 10:03:20.147 4470-4605/? I/HwLauncher: WeatherDynamicUpdaterpositiveUpdate at WeatherDynamicUpdater
12-21 10:03:20.147 4470-4470/? I/HwLauncher: DynamicIcon onResume  isvisible = false   mAttachedToWindow:true    mWindowVisible:falsecom.huawei.android.totemweather
12-21 10:03:20.148 4470-4470/? I/HwLauncher: DynamicUpdater registerReceiver
12-21 10:03:20.149 4470-4470/? I/HwLauncher: DynamicUpdater call updateFolder
12-21 10:03:20.149 4470-4470/? I/HwLauncher: DynamicIcon onResume  isvisible = false   mAttachedToWindow:true    mWindowVisible:falsecom.android.calendar
12-21 10:03:20.149 4470-4470/? I/HwLauncher: DynamicUpdater registerReceiver
12-21 10:03:20.151 4470-4470/? I/HwLauncher: DynamicUpdater call updateFolder
12-21 10:03:20.152 4470-4470/? I/HwLauncher: DynamicIcon onResume  isvisible = true   mAttachedToWindow:false    mWindowVisible:falsecom.android.deskclock
12-21 10:03:20.152 4470-4470/? I/HwLauncher: Launcher  Launcher.onStart() cost 7 ms
12-21 10:03:20.152 4470-4470/? I/HwLauncher: Launcher onResume()
12-21 10:03:20.152 4470-4470/? I/HwLauncher: Launcher doResumeWork()
12-21 10:03:20.156 4470-4470/? I/HwLauncher: Launcher  onResume mIsToUninstallApp = false
12-21 10:03:20.156 4470-4470/? I/HwLauncher: Launcher  Launcher hot start cost 12 ms
12-21 10:03:20.158 4470-4470/? I/HwSecImmHelper: mSecurityInputMethodService is null
12-21 10:03:20.162 19040-19060/? I/TotemWeather: Utils launcherIntent for weather DynamicIcon
12-21 10:03:20.164 4470-21333/? I/HwLauncher: Launcher.MotionManager startMotionAppsReco begin,flg = 402
12-21 10:03:20.166 19040-19060/? I/SendBroadcastPermission: action:com.huawei.android.action.launcher_weather_icon_change, mPermissionType:0
12-21 10:03:20.176 2904-2956/? I/[Gralloc]: alloc w[1080] h[1920] format[1] usage[2816]
12-21 10:03:20.177 4470-4605/? E/HwLauncher: SettingsEx , no such field.
12-21 10:03:20.177 4470-4605/? W/HwLauncher: Clock getDataFormat the getSystemString failed.
12-21 10:03:20.179 4470-4605/? I/HwLauncher: DynamicIconData , getDrawableForDynamic begin, pkg = com.android.deskclock, picName = deskclock_bg
12-21 10:03:20.179 4470-4605/? I/HwLauncher: DynamicIconData , getDrawableForDynamic end, pkg = com.android.deskclock, picName = deskclock_bg
12-21 10:03:20.180 2904-2956/? I/[Gralloc]: alloc succ handle[0x55b7d2ab90] stride[1120]
12-21 10:03:20.180 2904-2956/? I/[Gralloc]: alloc w[1080] h[1920] format[1] usage[2816]
12-21 10:03:20.182 4470-4605/? I/HwLauncher: ClockDynamicUpdater clock update folder at ClockDynamicUpdater
12-21 10:03:20.182 4470-4605/? I/HwLauncher: DynamicUpdater updateBitmap end and send update message
12-21 10:03:20.183 2904-2956/? I/[Gralloc]: alloc succ handle[0x55b7c290f0] stride[1120]
12-21 10:03:20.183 2904-2956/? I/[Gralloc]: alloc w[1080] h[1920] format[1] usage[2816]
12-21 10:03:20.186 2904-2956/? I/[Gralloc]: alloc succ handle[0x55b7c0e4e0] stride[1120]
12-21 10:03:20.186 4470-4470/? I/HwSecImmHelper: mSecurityInputMethodService is null
12-21 10:03:20.189 4470-4470/? I/HwLauncher: WeatherDynamicUpdaterreceive action = com.huawei.android.action.launcher_weather_icon_change
                                              stringArray[] [unknown]
12-21 10:03:20.203 3879-3879/? W/View: requestLayout() improperly called by com.android.systemui.statusbar.phone.IconMerger{5bb45f3 V.E...... ........ 0,0-162,72 #7f1000c3 app:id/notificationIcons} during second layout pass: posting in next frame
12-21 10:03:20.204 4470-21333/? W/MotionDetectionManager: startMotionAppsReco motionApps: 402 disabled
12-21 10:03:20.204 4470-21333/? W/HwLauncher: Launcher.MotionManager startMotionAppsReco service flg 402 is unavailable
12-21 10:03:20.204 4470-21333/? I/HwLauncher: Launcher.MotionManager , start MotionApps Reco end.
12-21 10:03:20.229 4470-4470/? I/HwLauncher: DynamicUpdater call updateFolder
12-21 10:03:20.290 3437-3771/? E/WifiConfigStore: updateConfiguration freq=2432 BSSID=00:a0:57:21:dd:c4 RSSI=-79 "eduroam"WPA_EAP
12-21 10:03:20.633 21334-21334/? I/appproc: CLASSPATH=/system/framework/am.jar
12-21 10:03:20.633 21334-21334/? I/appproc: Command=app_process /system/bin com.android.commands.am.Am force-stop de.waechtertroll.disciple 
12-21 10:03:20.638 21334-21334/? I/AndroidRuntime: readDownloadBoosterConfig: 'false'
12-21 10:03:20.692 21334-21334/? I/HWSERVICES: hwnative_get_component_register:libdrmbitmap,JNI
12-21 10:03:20.700 21334-21334/? E/HAL: load: id=memtrack != hmi->id=memtrack

                                        [ 12-21 10:03:20.702 21334:21334 I/         ]
                                        power log dlsym ok
12-21 10:03:20.704 21334-21334/? I/Radio-JNI: register_android_hardware_Radio DONE
12-21 10:03:20.712 4470-4790/? W/OpenGLRenderer: Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
12-21 10:03:20.712 4470-4790/? W/OpenGLRenderer: Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
12-21 10:03:20.714 21334-21334/? I/android_hardware_fm.cpp: register_android_hardware_fm_fmradio
12-21 10:03:20.714 21334-21334/? I/android_hardware_fm.cpp: ========64bit long size = 8
12-21 10:03:20.714 21334-21334/? I/android_hardware_fm.cpp: FM: get chip type = bcm43xx
12-21 10:03:20.715 21334-21334/? E/HAL: load: id=fm != hmi->id=fm
12-21 10:03:20.715 21334-21334/? E/fm_if.c: find the id:fm and begins to open the devices

That is the unfiltered stacktrace after I stepped into the crash. It happens during the setContentView(...)

android
android-layout
android-fragments
asked on Stack Overflow Dec 12, 2016 by waechtertroll • edited Dec 21, 2016 by waechtertroll

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0