0

我轉換我的活動片段,該方法network_reinit_activity精細工作過,但是當我在片段中運行它,它不會,這是方法:方法曾在活動,但不是在一個片段

private final Context c = getActivity(); 

private void network_reinit_activity() { 

    new Thread(new Runnable() { 
     @Override 
     public void run() { 
      Activity mainAct = (Activity)c; 
      Intent new_i = new Intent(getActivity(), NavigationActivity.class); 
     mainAct.finish(); 
     Intent srv_i = new Intent(c, RadioStreamService.class); 
     srv_i.putExtra("RS_STREAM_URL", RS_STREAM_URL); 
     getActivity().stopService(srv_i); 
     if(isInForeground) 
    //   startActivity(new_i); 
     } 
    }).run(); 


} 

回答

0

片段活動完成後,請看下面的代碼

new Thread(new Runnable() { 
     @Override 
     public void run() { 
      Activity mainAct = (Activity)c; 
      Intent new_i = new Intent(getActivity(), NavigationActivity.class); 
      getActivity().onBackPressed() // to finish fragment 
      Intent srv_i = new Intent(c, RadioStreamService.class); 
      srv_i.putExtra("RS_STREAM_URL", RS_STREAM_URL); 
      getActivity().stopService(srv_i); 
      if(isInForeground) 
      //   startActivity(new_i); 
      } 
    }).run(); 
+0

謝謝你的幫助; – fayza

+0

歡迎:) – Deepak

相關問題