2121import android .app .Fragment ;
2222import android .app .FragmentManager ;
2323
24- import android .support .v4 .content .WakefulBroadcastReceiver ;
25- //import android.content.BroadcastReceiver;
24+ import android .content .BroadcastReceiver ;
2625import android .content .Context ;
2726
2827
@@ -242,8 +241,7 @@ public void onResume() {
242241
243242 @ Override
244243 public void onPause () {
245- unloadReceiver ();
246-
244+
247245 if (errorDialog != null ) {
248246 errorDialog .dismiss ();
249247 }
@@ -253,6 +251,7 @@ public void onPause() {
253251 @ Override
254252 public void onDestroyView () {
255253 Log .d ("ondestroyView" ,"called" );
254+ unloadReceiver ();
256255 step1Label = null ;
257256 step2Label = null ;
258257 step3Label = null ;
@@ -1022,7 +1021,7 @@ public void updateUI(){
10221021 }
10231022
10241023
1025- public static class MyReceiver extends WakefulBroadcastReceiver {
1024+ public static class MyReceiver extends BroadcastReceiver {
10261025
10271026 private PwnixSetupFragment fragment ;
10281027
@@ -1032,36 +1031,35 @@ public void setCallback(PwnixSetupFragment f){
10321031
10331032 @ Override
10341033 public void onReceive (Context context , Intent intent ) {
1035- if (fragment .isAdded ()) { // make sure the fragment is attached before doing anything
1036- Bundle extras = intent .getExtras ();
1037- String words = extras .getString ("stage" );
1038- if (words != null ) {
1039- Toast .makeText (context , "Received: " + words , Toast .LENGTH_SHORT ).show ();
1040- }
1034+ if ( fragment != null ) {
1035+ if (fragment .isAdded ()) { // make sure the fragment is attached before doing anything
1036+ Bundle extras = intent .getExtras ();
1037+ String words = extras .getString ("stage" );
1038+ if (words != null ) {
1039+ Toast .makeText (context , "Received: " + words , Toast .LENGTH_SHORT ).show ();
1040+ }
10411041
1042- int progress = extras .getInt ("progress" );
1042+ int progress = extras .getInt ("progress" );
10431043
1044- // update progress
1045- if (progress < 100 && progress >= 0 ) {
1046- fragment .updateDLProgress (progress );
1047- }
1044+ // update progress
1045+ if (progress < 100 && progress >= 0 ) {
1046+ fragment .updateDLProgress (progress );
1047+ }
10481048
1049- try {
1050- if (words != null ) {
1051- PwnixSetupFragment .PwnixInstallState replyState = PwnixSetupFragment .PwnixInstallState .valueOf (words .toUpperCase ());
1049+ try {
1050+ if (words != null ) {
1051+ PwnixSetupFragment .PwnixInstallState replyState = PwnixSetupFragment .PwnixInstallState .valueOf (words .toUpperCase ());
10521052
1053- if (fragment .fragmentState == PwnixSetupFragment .PwnixInstallState .VERIFICATION_ERROR && replyState == PwnixSetupFragment .PwnixInstallState .DOWNLOADING ){
1054- return ; // ignore
1053+ if (fragment .fragmentState == PwnixSetupFragment .PwnixInstallState .VERIFICATION_ERROR && replyState == PwnixSetupFragment .PwnixInstallState .DOWNLOADING ){
1054+ return ; // ignore
1055+ }
1056+ fragment .setState (replyState );
1057+ fragment .updateUI ();
10551058 }
1056- fragment . setState ( replyState );
1057- fragment . updateUI ();
1059+ } catch ( java . lang . IllegalArgumentException e ) {
1060+ //the intent extra contains a string that is not a PwnixInstallState
10581061 }
1059- } catch (java .lang .IllegalArgumentException e ) {
1060- //the intent extra contains a string that is not a PwnixInstallState
1061- }
1062- } else {
1063- //fragment is not on the screen
1064- Log .d ("Received WHILE NOT ON SCREEN" , "SOMETHING" );
1062+ }
10651063 }
10661064 }
10671065 }
0 commit comments