android - Application abnormal behavior does not start activity mentioned in intent -


i have 3 major class in application

1) intent service: receive push notification , open activity according notification message , other 2 classes behavior. below code that

 if(global.ismainscreenrunning){    intent intent = new intent(this, mainscreen.class);    intent.setflag(intent.flag_activity_new_task);    startactivity(intent); } else if(!global.notificationscreenrunning){    intent intent = new intent(this, notificationscreen.class);    intent.setflag(intent.flag_activity_new_task);    startactivity(intent); } 

2) notificationscreen : mediator screen if application not running screen shown first , on click of yes button of screen mainscreen opened , screen finished.

3) main screen: main screen of application show map. core behavior ts launchmode="singletask" mentioned in menifest file, means if screen running hole data sent onnewintent() method rather opening screen again.

now happening in flow is

step 1: application in background , push notification comes. condition run , second condition gets success , notification screen intent shot

step 2: in notification screen click on ye button move on next main screen

step 3: in main screen process info , perform task or close application

step 4: again new notification received , application not running goes second condition , start intent notification screen time no notification screen launched instead of providing intent , main screen launched wrong.

this abnormal behavior facing instead of providing class of notification screen intent main screen launched totally different behavior of application according android.

any 1 come across such problem appreciated.

edit

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.app"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="15"         android:targetsdkversion="18" />      <uses-permission android:name="android.permission.internet" />     <uses-permission android:name="android.permission.record_audio" />     <uses-permission android:name="android.permission.camera" />     <uses-permission android:name="android.permission.write_external_storage" />     <uses-permission android:name="android.permission.access_fine_location" />     <uses-permission android:name="android.permission.access_coarse_location" />     <uses-permission android:name="android.permission.access_mock_location" />     <uses-permission android:name="android.permission.access_network_state" />     <uses-permission android:name="android.permission.wake_lock" />      <uses-feature android:name="android.hardware.camera" />     <uses-feature android:name="android.hardware.camera.front" />     <uses-feature android:name="android.hardware.camera.autofocus" />     <uses-feature android:name="android.hardware.microphone" />      <uses-permission android:name="android.permission.read_contacts" />     <uses-permission android:name="android.permission.get_accounts" />      <uses-permission android:name="com.google.android.c2dm.permission.receive" />      <permission android:name="com.example.app.permission.c2d_message"         android:protectionlevel="signature" />     <uses-permission android:name="com.example.app.permission.c2d_message" />      <supports-screens         android:largescreens="true"         android:normalscreens="true"         android:smallscreens="true"         android:xlargescreens="true" />      <application         android:allowbackup="true"         android:icon="@drawable/android_app_icon"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name=".splashscreen"             android:configchanges="keyboardhidden|orientation"             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>          <activity             android:name=".mainscreen"             android:configchanges="keyboardhidden|orientation"             android:launchmode="singletask"             android:excludefromrecents="true"             android:screenorientation="portrait" >         </activity>         <activity             android:name=".notificationscreen"             android:configchanges="keyboardhidden|orientation"             android:excludefromrecents="true"             android:screenorientation="portrait" >         </activity>          <receiver             android:name=".pushnotification.gcmbroadcastreceiver"             android:permission="com.google.android.c2dm.permission.send" >             <intent-filter>                 <action android:name="com.google.android.c2dm.intent.receive" />                 <category android:name="com.selebrety.app" />             </intent-filter>         </receiver>          <service android:name=".pushnotification.gcmintentservice" />          <meta-data android:name="com.google.android.gms.version"            android:value="@integer/google_play_services_version" />     </application>  </manifest> 

second edit

the mobile in testing "yu yureka" here specification link. current have android 5.0.2 os

third edit

to test behavior have debugged code eclipse debugger. check have put break point in notificationscreen onresume , oncreate never hit instead of onresume of mainscreen hit.

also added logs in if , else condition still logs else condition printed.

fourth edit global.ismainscreenrunning: global boolean variable done false in onpause of mainscreen , done true in onresume of mainscreen.

global.notificationscreenrunning: global boolean variable done false in onpause of notificationscreen , done true in onresume of notificationscreen.

global state evil, , question demonstrates why. understand what's happening, you'll have @ every place global flags set or cleared, , analyze possible execution paths might lead there. that's way beyond scope of kind of can on so. , there's complication on android, since entire vm might destroyed (and globals cleared) time app in background. bad, vm , application instance might retained after exit last activity. when happens, application#oncreate(...) not called again next time start app, , static globals still set whatever when last ran app.

save lot of hair-pulling , stop using global state.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -