Android App重启

时间:2013-04-26 10:30:07

标签: android

我正在开发基于计时器的应用程序。无论应用程序位于前台还是后台,计时器都会在其中一个活动中连续运行。使用单独的计时器每隔一秒编写一个单独的服务来记录GPS。活动计时器负责根据特定条件启动和停止服务。我扩展了Application类并重写了onCreate和onTerminate事件。

public class MyApplication extends Application.

和 的AndroidManifest.xml

   <application
        android:allowBackup="true"
        android:icon="@drawable/launcher_icon"
        android:label="@string/app_name"
        android:persistent="true"
        android:theme="@style/AppTheme"
        android:name="MyApplication"
         >

服务

public class GPSLoggingService extends Service

当应用程序在后台运行并且有时在前台运行时,onCreate会执行几次,如果服务正在运行,它也会重新启动。

经常重启应用程序和解雇MyApplication类的onCreate可能是什么原因。这个问题的解决方案是什么?

请帮助我,因为我在过去3天尝试解决此问题

这是完整的androidmanifest文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ab.xy.cd"
    android:versionCode="1"
    android:versionName="2.0.5.15" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/launcher_icon"
        android:label="@string/app_name"
        android:persistent="true"
        android:theme="@style/AppTheme"
        android:name="MyApplication"
         >

        <!-- Since application is using map add following -->
        <uses-library android:name="com.google.android.maps" />

        <activity
            android:name="ab.xy.cd.ui.Splash"
            android:label="@string/app_name" 
            >
             <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="ab.xy.cd.ui.Login"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustPan" 
            >
        </activity>
        <!--
             stateHidden is required if you dont want to show keyboard when activity starts and 
             edit text gets focus. In this case if user clicks on any edit text the on the same
             layout, the keyboard will be poped up 
        -->
        <activity
            android:name="ab.xy.cd.ui.BasicSettings"
            android:label="@string/app_name"
            android:windowSoftInputMode="stateHidden|adjustPan"
             >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.MainActivity"
            android:configChanges="orientation|screenSize"
            android:label="@string/app_name"
            android:theme="@style/Theme.NoBackground"
            android:hardwareAccelerated="true" 
            >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.Challenges"
            android:label="@string/app_name" 
            >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.Slim"
            android:label="@string/app_name"
            android:windowSoftInputMode="stateHidden|adjustPan" 
            >

        </activity>
        <activity
            android:name="ab.xy.cd.ui.Score"
            android:label="@string/app_name" 
            >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.Settings"
            android:configChanges="orientation|screenSize"
            android:label="@string/app_name" 
            >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.TextSummary"
            android:configChanges="orientation|screenSize"
            android:label="@string/app_name" 
            >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.EventSetting"
            android:label="@string/app_name"
             >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.AboutMapAndTraffic"
            android:label="@string/app_name"
            >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.AboutUs"
            android:label="@string/app_name"
             >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.VersionInformation"
            android:label="@string/app_name" 
            >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.Language"
            android:label="@string/app_name" 
            >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.Search"
            android:label="@string/app_name"
             >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.TutorialFromLogin"
            android:label="@string/app_name" 
            >
        </activity>
        <activity
            android:name="ab.xy.cd.ui.Tutorial"
            android:label="@string/app_name" 
            >
        </activity>
        <activity
            android:name="ab.xy.cd.ShutdownActivity"
            android:label="@string/app_name" 
            >
        </activity>
        <activity
            android:name="ab.xy.cd.ExtraFor"
            android:label="@string/app_name"
             >
        </activity>

        <service android:name=".GPSLoggingService"
            android:process=":gpslogging"
            >
        </service>

        <receiver
            android:name="ab.xy.cd.utils.NetworkStateInformer"
            android:label="NetworkStateInformer" >
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" >
                </action>
            </intent-filter>
        </receiver>
         <receiver android:name="ab.xy.cd.utils.RushHourReceiver">
        </receiver>
        <receiver android:name="ab.xy.cd.utils.ServiceStartReceiver">
        </receiver>
        <receiver android:name="ab.xy.cd.utils.ServiceEndReceiver">
        </receiver>
    </application>

</manifest>

0 个答案:

没有答案