当应用程序从缓存中清除应用程序的怪事

问题描述:

大家好,感谢您的阅读。

Hello all and thanks for reading.

这个问题是实物我原来的职位这里问题的追踪。
Main一段时间闲置的应用程序的活动后进度条和打击通过文字复位。不过,我现在已经制定了这是怎么回事,但仍需要就如何解决它的一些建议。

This question is kind of a follow on question from my original post here. Main activity progress bars and strike through text reset after a period of app inactivity. However, I've now worked out what's going on but still need some advice on how to solve it.

只是为了回顾一下...

Just to recap...

基本上,我写了一个使用了一些这些编程方式创建的播放列表中的每首曲目标题下方标准的进度条的媒体播放器应用程序。每一个进度条跟踪其位于下在播放列表中的歌曲的进度。

Basically I have written a media player app that uses a number of standard progress bars which are created programmatically underneath each track title in the playlist. Each progress bar tracks the progress of the song its sits underneath in the playlist.

我也用下面的code在我的清单,以确保应用程序总是返回到相同的主要活动。

I also use the following code in my manifest to make sure the app always returns to the same main activity.

android:alwaysRetainTaskState="true"
android:launchMode="singleTask"

现在我的问题是,当用户返回到主屏幕,然后重新登场,为期30至60分钟后,该应用程序虽然一切是因为它是 - 如果进度条是只有部分满(即跟踪已暂停或停止的一半),一下子跃升了100%。

Now the problem I have is that when the user returns to the home screen and then relaunches the app after a period of 30 to 60 minutes although everything else is as it was - if the progress bar was only partially full (i.e. the track has been paused or stopped halfway through) all of a sudden its jumped to 100%.

我发现,当应用程序缓存的过程中碰撞出榜单其他应用月底发生这种情况。即我可以重新创建问题马上通过暂停应用程序,然后打开其他应用程序的负载,然后回去吧。我还注意到,当它不再出现在缓存的进程列表的OnCreate也被调用,所以它看起来像应用程序已经被关闭,其本质上重新创建活动。但是,什么是奇怪的是,有$ P $进度条pviously被设置为某个值突然得到与设置为100%进度重建。进展

I discovered that this happens when the apps cached process is bumped off the end of the list by other apps. I.e. I can recreate the issue straight away by pausing the app and then opening loads of other apps and then going back to it. I also noticed that when it no longer appears in the cached process list "oncreate" also gets called so it looks like the app has been closed and its essentially recreating the activity. However, what is odd is that the progress bars that have previously been set to some value suddenly get recreated with progress set to 100%. Progress

现在,如果他们正在重新肯定自己的进步应该默认为0?我甚至尝试设置进步创建它们为0时(即myprogbar.setProgress =(0),但是这似乎没有什么区别。

Now if they are being recreated surely their progress should default to 0? I even tried setting the progress when they are created to 0 (i.e. myprogbar.setProgress=(0) but this seemed to make no difference.

我怎么能...

一个。确保进度条设置为0在创建时?

a. Ensure that the progress bars are set to 0 when they are created?

乙。期间的OnCreate检查应用程序已经运行,并摧毁它的所有previous版本?

b. Check during oncreate if the app is already running and destroy all previous versions of it?

℃。确保应用程序不会从缓存的过程少了?

c. Ensure that the app doesn't get dropped from the cached processes?

Ð。解决这一问题的其他方法。

d. Some other way of solving the issue.

我AP preciate我大概可以创建一个循环,通过进度条循环一旦被创建和重置他们,但我想明白的地方进度条让100%,该值以及如何涉及的应用程序被挤出缓存进程列表中。

I appreciate I could probably create a loop that loops through the progress bars once they have been created and resets them but I'm trying to understand where the progress bars are getting this value of 100% and how this relates to the app being pushed out of the cached processes list.

非常感谢

不幸的是我从来没有工作,为什么这是实际发生的事情,但为了以防万一别人永远得到我发现周围的工作同样的问题。

Unfortunately I never worked out why this was actually happening but just in case someone else ever gets the same issue I found a work around.

基本上,我成立了一个定时器,遍历所有屏幕上的进度条,并重新设置活动负载时。不优雅,或聪明,但它的工作原理。

Basically I set up a timer to loop through all of the progress bars on screen and reset them when the activity loads. Not elegant or smart but it works.

    final Timer myTimer = new Timer();
    myTimer.schedule(new TimerTask() {
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    ProgressBar temppb;
                    for (int i = 0; i < (totalnumberofprogressbars); i++) {
                            temppb = (ProgressBar) findViewById(i + 1);
                            temppb.setProgress(0);
                    }
                }
            });

            myTimer.cancel();
        }
    }, 50,50);