編輯:發現它與我的消息接收推送通知服務的問題。如果我在關閉應用程序停止服務的問題不會再出現,但如果我在我的手機收到的通知點擊,它開始我的應用程序從錯誤的活動...... 我messagereceivingservice.java我做我的Android應用程序自動啓動
postNotification(new Intent(context, NotificationsActivity.class), context);
所以這是問題嗎?
我正在做一個android應用程序,用戶可以創建自己的配置文件與他們的朋友進行交互。該應用程序包括谷歌地圖和推送通知的實施。 我無法找到,因爲當這種情況發生時,但一段時間後,如果用戶停止或關閉應用,應用會在一段時間後自動重新啓動。 因爲我不能在這裏發佈我所有的代碼,有沒有人遇到過這個問題,並有一個想法在哪裏尋找這個問題的根源?可能是在關閉應用程序以重新啓動應用程序時運行的任何服務?我必須說我非常絕望,因爲除了這個問題之外,應用程序本身完全運行。
至少這是我的AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- GCM -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- GOOGLE CLOUD MESSAGING -->
<permission
android:name=".permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name=".permission.C2D_MESSAGE" />
<!-- if you want to keep processor from sleeping when a message is received -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider1496945817221747"
android:exported="true" />
<application
android:largeHeap="true"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<activity
android:name=".SplashScreen"
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=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
</activity>
<activity
android:name=".AddActivity"
android:label="@string/title_activity_add"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".DiscoverActivity"
android:label="@string/title_activity_discover"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".DetailActivity"
android:label="@string/title_activity_detail"
android:parentActivityName=".MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<activity
android:name=".ProfileActivity"
android:label="@string/title_activity_profile"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<activity
android:name=".EditProfileActivity"
android:label="@string/title_activity_edit_profile"
android:parentActivityName=".ProfileActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ProfileActivity" />
</activity>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps"
android:screenOrientation="portrait" >
</activity>
<!-- FACEBOOK ACTIVITY -->
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name=".FriendsActivity"
android:label="@string/title_activity_friends"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<activity
android:name=".RegisterActivity"
android:label="@string/title_activity_register"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<activity
android:name=".NotificationsActivity"
android:label="@string/title_activity_notifications"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<!-- GCM -->
<!-- android:name="com.google.android.gms.gcm.GcmReceiver" -->
<receiver
android:name=".ExternalReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="com.google.android.c2dm.intent.REGISTER" />
<category android:name=".androidtest" />
</intent-filter>
</receiver>
<service
android:name=".NotificationService"
android:exported="false" >
</service>
<service
android:name=".LoadImageService"
android:exported="false" >
</service>
<service
android:name=".AddFriendService"
android:exported="false" >
</service>
<service
android:name=".AcceptFriendService"
android:exported="false" >
</service>
<service
android:name=".JoinService"
android:exported="false" >
</service>
<service
android:name=".DeleteService"
android:exported="false" >
</service>
<activity
android:name=".EditActivity"
android:label="@string/title_activity_edit"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
<service
android:name=".MessageReceivingService"
android:label=".MessageReceivingService" >
<intent-filter>
<action android:name=".AndroidMobilePushApp" />
<action android:name=".ExternalReceiver" />
<category android:name=".androidtest" />
</intent-filter>
</service>
<activity
android:name=".BasesActivity"
android:label="@string/title_activity_bases"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
</activity>
</application>
是我做的。那我該如何處理呢?發現它與我的消息接收服務有關的問題。如果我停止關閉應用程序的服務,問題不會再出現,但如果我點擊手機中收到的通知,它會從錯誤的活動啓動我的應用程序... – rudi
您可以使用PendingIntent指定活動。請參閱http://stackoverflow.com/questions/13716723/open-application-after-clicking-on-notification 或http://developer.android.com/intl/ru/training/notify-user/navigation。 html 您可以設置backstack的行爲,例如 –
我已經在postNotification方法中使用了掛起的意圖 – rudi