well i have one problem with parse, but i can´t know why it crashes, i explain it.
Im working with parse, and works ok, but then with no reason, sometimes, when i turn off the mobile or go out of the wifi´s range, the app crashes. i think all its ok, cause i can recieve parse´s notifications with no problem.... well need some help here
The app its a webview
public class MainActivity extends Activity {
private WebView myWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.activity_main);
Parse.initialize(getApplicationContext(), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveEventually();
this.myWebView = (WebView) this.findViewById(R.id.web);
myWebView.getSettings().setJavaScriptEnabled(true);
//iniciamos javascript
myWebView.addJavascriptInterface(new WebAppInterface(this),"Android");
//webviewclient para websettings
WebSettings websettings= myWebView.getSettings();
websettings.setJavaScriptEnabled(true);
myWebView.setWebViewClient(new MyWebViewClient());
myWebView.loadUrl("http://www.aaaaa.com/);
}
#Override
public void onBackPressed(){
if(this.myWebView.canGoBack())
this.myWebView.goBack();
else
super.onBackPressed();
}
private class MyWebViewClient extends WebViewClient{
#SuppressWarnings("unused")
private long loadTime;
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
if (Uri.parse(url).getHost().equals("www.aaaaa.com")) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
public class ParseBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "com.parse.ParseBroadcastReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "received " + intent.getAction());
PushService.startServiceIfRequired(context);
}
}
}
}
and then the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jor.dietd"
android:versionCode="3"
android:versionName="1.2" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.jor.dietd.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.jor.xxxxxx.permission.C2D_MESSAGE" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.jor.xxxxx.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
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" />
<category android:name="com.jor.xxxx" />
</intent-filter>
</receiver>
</application>
</manifest>
Related
This is my service:
public class KeepAliveService extends Service {
Alarm alarm = new Alarm();
public void onCreate()
{
Log.i("","KEEPALIVE onCreate");
super.onCreate();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId)
{
alarm.setAlarm(this);
Log.i("","KEEPALIVE onCreate start command");
return START_STICKY;
}
#Override
public void onStart(Intent intent, int startId)
{
alarm.setAlarm(this);
Log.i("","KEEPALIVE onStart");
}
#Override
public IBinder onBind(Intent intent)
{
return null;
}
}
I have it declared like this in my manifest, after my :
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<application
android:icon="#drawable/ic_launcher"
android:name="com.vidyo.vidyomod.VidyoModApplication"
android:theme="#style/AppTheme"
android:label="#string/app_name"
android:allowBackup="true"
android:supportsRtl="true"
tools:replace="android:icon">
<activity
android:name="com.vidyo.vidyomod.activities.BaseActivity"
android:label="#string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="vidyocore" />
</intent-filter>
</activity>
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
</service>
<receiver android:process=":remote" android:name="com.vidyo.vidyomod.utils.Alarm"></receiver>
<receiver android:name="com.vidyo.vidyomod.utils.AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
And on my onCreate of my BaseActivity, I do this:
Intent i= new Intent(BaseActivity.this, KeepAliveService.class);
startService(i);
I debugged, my breakpoint at startService does stop, but OnCreate is not called. why?
You have to put your Service and your BroadcastReceiver inside your application tag:
<application>
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
</service>
<receiver android:name="com.vidyo.vidyomod.utils.AutoStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
</application>
Also, you are starting service in a different process.
<service
android:name="com.vidyo.vidyomod.KeepAliveService"
android:enabled="true"
android:process=":your_service" >
The debugger is attached to your main process. When the new one starts, it has no debugger attached, so it will ignore your breakpoints.
I am using FCM with data-messaging and can handle both foreground and background notification, but can't receive them when a phone is rebooted or app is killed (task is terminated by swiping in task manager).
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tadad.firebasetestDOUBLE">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name="com.example.tadad.firebasetestDOUBLE.AndroidApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.example.tadad.firebasetestDOUBLE.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Notification -->
<service
android:name="com.example.tadad.firebasetestDOUBLE.notification.SomeInstanceIDListenerService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name="com.example.tadad.firebasetestDOUBLE.notification.SomeFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
Code:
public class SomeFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
int a = 4;
sendNotification("Smth", "Receive please!");
}
}
public class SomeInstanceIDListenerService extends FirebaseInstanceIdService {
#Override
public void onTokenRefresh() {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(String token) {
// TODO: Implement this method to send token to your app server.
}
}
Im sending a push message with a custom action but in the onPushReceive the action that I get is com.parse.push.intent.RECEIVE instead of com.hellboy.beat.STATUS_DONE
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hellboy.beat"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- permission required to use Alarm Manager -->
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<!-- permission required for Notification -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- permission required to Send SMS -->
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- permission required to get Location & Number -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- permission required to Vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />
<!-- permission required to use Parse -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- permission required to use Parse Push -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.parse.starter.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.hellboy.beat.permission.C2D_MESSAGE" />
<application
android:name="com.hellboy.beat.Application"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.hellboy.beat.main.Activity_main"
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="com.hellboy.beat.login.Activity_login" />
<activity android:name="com.hellboy.beat.requests.Activity_requests" />
<activity android:name="com.hellboy.beat.settings.Activity_settings" />
<!-- Register the Notification Receiver -->
<service android:name="com.parse.PushService" />
<!-- Regular Push Notification -->
<receiver android:name="com.parse.ParseBroadcastReceiver" />
<!-- Our Reciver -->
<receiver
android:name="com.hellboy.beat.PushRec"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.hellboy.beat.STATUS_DONE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
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" />
<!-- IMPORTANT: Change "com.parse.starter" to match your app's package name. -->
<category android:name="com.hellboy.beat" />
</intent-filter>
</receiver>
</application>
</manifest>
PushRec.java
public class PushRec extends ParsePushBroadcastReceiver
{
private static final String TAG = "BEAT_PUSHREC";
Context context;
#Override
public void onPushReceive(Context context, Intent intent)
{
this.context = context;
Log.i(TAG, "Receiver");
if (intent == null)
{
Log.i(TAG, "Receiver intent null");
}else
{
Log.i(TAG, "Receiver intent not null");
String action = intent.getAction();
Log.i(TAG, "got action " + action );
if (action.equals("com.hellboy.beat.STATUS_DONE"))
{
//DOES NOT COME OVER HERE
}
}
}
}
Sending-Push:
ParseQuery<ParseInstallation> pushQuery = ParseInstallation.getQuery();
pushQuery.whereMatchesQuery("user", subscriberQuery);
JSONObject obj=null;
obj =new JSONObject();
try
{
obj.put("action","com.hellboy.beat.STATUS_DONE");
obj.put("statusdone_message" , message);
} catch (JSONException e1) {
e1.printStackTrace();
}
//TODO move this to the 'cloud'
ParsePush pPush = new ParsePush();
pPush.setQuery(pushQuery);
pPush.setData(obj);
pPush.sendInBackground();
NOTE: My understanding is I'm making a mistake in the Manfiest since the notification arrives, but the wrong action is called
You can override onReceive method to dispatch your custom action.
#Override
public void onReceive(Context context, Intent intent) {
String intentAction = intent.getAction();
switch (intentAction) {
case "com.hellboy.beat.STATUS_DONE":
onPushReceive(context, intent);
break;
case ACTION_PUSH_DELETE:
onPushDismiss(context, intent);
break;
case ACTION_PUSH_OPEN:
onPushOpen(context, intent);
break;
}
}
https://github.com/ParsePlatform/Parse-SDK-Android/blob/master/Parse/src/main/java/com/parse/ParsePushBroadcastReceiver.java
The error was in the Manifest; ParseBroadcastReceiver should be ParsePushBroadcastReceiver
Snippet:
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.hellboy.beat.PushRec" >
<intent-filter>
<action android:name="com.hellboy.beat.STATUS_DONE" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
And remove this from the Manifest:
<!-- Regular Push Notification -->
<!-- REMOVE THIS -->
<receiver android:name="com.parse.ParseBroadcastReceiver" />
Also in the Receiver:
public class PushRec extends ParsePushBroadcastReceiver
{
}
becomes
public class PushRec extends BroadcastReceiver
{
}
I just updated the latest Parse SDK (1.11.0) and now I'm not receiving push notifications. I am able to register successfully and can see on the parse site that that my "developer" channel has been subscribed but pushes never get sent and I get this error:
PPNS - Outdated device - The records on this installation are
outdated, the user might have uninstalled the app.
Can someone please take a look at my code and see if you notice anything incorrect?
public class LSIApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "********", "********");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("developer", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
}
}`
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="${applicationId}.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="${applicationId}.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.telephony" android:required="false" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<permission android:protectionLevel="signature"
android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application android:name=".LSIApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="********" />
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name=".startup.PushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
Note: The ${applicationId} is 'com.broker.schlisimobile.dev' and/or 'com.broker.schlisimobile' depending on whether it's a production or developer build.
Here is my custom PushBroadcastReceiver class:
public class PushBroadcastReceiver extends ParsePushBroadcastReceiver {
#Override
protected void onPushOpen(Context context, Intent intent) {
if ( storyJSONExists(intent) ) {
if (!DataController.getInstance().getCurrentUser().isGuestUser() ) {
Intent i = new Intent(context, PushLoadingActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
} else {
Intent i = new Intent(context, HomeActivity.class);
i.putExtra("promptForLogin", true);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
}
} else {
Intent i = new Intent(context, HomeActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.putExtras(i);
context.startActivity(i);
}
}
private boolean storyJSONExists(Intent intent) {
try {
String jsonString = intent.getExtras().getString("com.parse.Data");
JSONObject json = new JSONObject(jsonString);
if ( json.has("postID") ) {
return true;
}
} catch (JSONException jsonE) {
jsonE.printStackTrace();
}
return false;
}
}
In your manifest.xml comment/delete below code,
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
then add below code in manifest.xml
<receiver
android:name="com.parse.GcmBroadcastReceiver"
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" />
<!--IMPORTANT: Change "com.parse.starter" to match your app's package name.-->
<category android:name="your_application_id" />
</intent-filter>
</receiver>
hope it works.
The steps that explains the problem I faced are below;
1. I start the android application.
2. I put it on backgorund by pressing home button.
3. I turn the screen off.
4. I turn the screen on after some seconds.
5. My application suddenly becomes foreground. I realised that the application is forced to start again and the application class that I used is created again and then the start page of my application (this is login page) is shown although what page is opened before the step 2.
What I have tried so far is below;
I put configChanges and screenOrientation in all the activiy tags in my Androidmanifest.xml (I tried to put them one by one and both together also.)
<activity android:configChanges="orientation|keyboardHidden|screenSize"
android:name="com.myproject.Activity"
android:screenOrientation="nosensor"/>
I also tried to use screenOrientation="portrait" but didn't work.
My problem is related with the How do I disable orientation change on Android?, Prevent Android activity from being recreated on turning screen off and like others, but I could not find the solution of my problem yet.
Can you please help?
Edit 1: ********************************
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myproject"
android:versionCode="1"
android:versionName="1.0"
xmlns:tools="http://schemas.android.com/tools" >
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<!-- Permission to use NFC -->
<uses-permission android:name="android.permission.NFC" />
<uses-feature
android:name="android.hardware.nfc.hce"
android:required="true" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<permission android:name="com.myproject.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.myproject.permission.C2D_MESSAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<!--
Add this permission to check which network access properties (e.g.
active type: 3G/WiFi).
-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Add this permission to access WLAN MAC address. -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- Add this permission to access HW ID. -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<application
android:name="com.myproject.hce.MyApplication"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/MyAppTheme"
tools:replace="android:icon,android:theme"
>
<!-- Splash Activity -->
<activity android:configChanges="orientation|keyboardHidden|screenSize"
android:name=".Splash"
android:theme="#android:style/Theme.Holo.Light.NoActionBar"
android:windowSoftInputMode="stateHidden"
android:screenOrientation="nosensor" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Login Activity -->
<activity android:configChanges="orientation|keyboardHidden|screenSize"
android:name="com.myproject.LoginView"
android:screenOrientation="nosensor"
android:windowSoftInputMode="adjustResize" >
</activity>
<activity android:configChanges="orientation|keyboardHidden|screenSize"
android:name="com.myproject.MainView"
android:screenOrientation="nosensor" >
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/fb_app_id" />
<meta-data
android:name="com.crashlytics.ApiKey"
android:value="12h3g21h4v32hv43hv4" />
<service
android:name="com.myproject.pushnotifications.GCMIntentService"
android:enabled="true" >
</service>
<service
android:name="com.myproject.hce.McbpHceService"
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE" >
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="#xml/apduservice" />
</service>
<receiver
android:name="com.myproject.pushnotifications.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RETRY" />
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>
<service
android:name="com.myproject.hce.MyService"
android:exported="true"
android:enabled="true"
android:stopWithTask="false"/>
</application>
</manifest>
Application class
public class MyApplication extends Application {
private static MyApplication MyApplication;
private MyActivityLifeCycleCallbacks MyActivityLifeCycleCallbacks;
public static MyApplication getMyApplication() {
return MyApplication;
}
#Override
public void onCreate() { //coko1
MyLog.i(UtilConstants.LOG_TAG_HCE, "MyApplication " + "onCreate ...");
if (MyApplication == null)
MyApplication = this;
else
return;
MyLog.i(UtilConstants.LOG_TAG_HCE, "MyApplication " + "super.onCreate() ...");
super.onCreate();
registerActivityLifecycleCallbacks(new MyLifecycleHandler());
setMyActivityLifeCycleCallbacks(new MyActivityLifeCycleCallbacks());
registerActivityLifecycleCallbacks(getMyActivityLifeCycleCallbacks());
}
public MyActivityLifeCycleCallbacks getMyActivityLifeCycleCallbacks() {
return MyActivityLifeCycleCallbacks;
}
public void setMyActivityLifeCycleCallbacks(
MyActivityLifeCycleCallbacks MyActivityLifeCycleCallbacks) {
this.MyActivityLifeCycleCallbacks = MyActivityLifeCycleCallbacks;
}
}
Edit 2:****************
Splash.java
public class Splash extends Activity {
public static Context context;
public static final String LOG_TAG = "Splash ";
#Override
public void onCreate(Bundle bundle)
{
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onCreate...");
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); // catch unexpected error
super.onCreate(bundle);
context = this;
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "MainView starts...");
Intent mainIntent = new Intent(Splash.this, MainView.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
#Override
protected void onResume() {
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onResume ...");
super.onResume();
}
}
MainView.class
public class MainView extends Activity {
Context context;
String LOG_TAG = "MainView ";
#Override
public void onCreate(Bundle savedInstanceState)
{
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onCreate ...");
super.onCreate(savedInstanceState);
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
context = this;
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "LoginView starts...");
Intent loginIntent = new Intent(Splash.this, LoginView.class);
Splash.this.startActivity(loginIntent);
Splash.this.finish();
}
#Override
protected void onResume() {
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onResume ...");
super.onResume();
}
#Override
protected void onStart() {
super.onStart();
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onStart ...");
};
#Override
protected void onPause() {
super.onPause();
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onPause ...");
};
#Override
protected void onDestroy() {
MyLog.i(UtilConstants.LOG_TAG_HCE, LOG_TAG + "onDestroy ...");
super.onDestroy();
};
}
Edit 3:****************
I use fragments, maybe this will be the reason, but I am not sure.
The problem is due to a library I used. It works in background and makes the application restarts.
I suspend it when the application goes to background and resume it when it comes foregorund. That is it, the problem is solved.
Thanks you anyway.