2016-03-22 140 views
0

說明: 我有抽屜式導航欄,其中有多個fragments.Like HomeFragmentfirstFragmentsecondFragment等 在HomeFragment,我打電話給我在其中傳遞的意圖,從適配器到另一個活動適配器。爲什麼按下活動按鈕後應用程序關閉?

當我按下活動應用程序的後退按鈕時直接關閉而不是後退。

這裏是我的適配器,我傳遞的意圖,另一個活動

itemView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       String key=lst_key.get(position); 
       String status_value=list_status.get(position); 
       if(status_value.equals("notstarted")){ 
        Log.e("MATCH_KEY",""+key); 
        Intent intent=new Intent(context,NotStartedMatchDetails.class); 
        intent.putExtra("mainobj", lst.get(position).toString()); 
        context.startActivity(intent); 


//     MainActivity mainActivity=(MainActivity)context; 
//     Intent intent=new Intent(context,SummaryCard.class); 
//     intent.putExtra("Key",key); 
//     intent.putExtra("access_token",mainActivity.getMyData()); 
//     context.startActivity(intent); 
       } 
       if(status_value.equals("started")){ 
        Log.e("MATCH_KEY",""+key); 
        MainActivity mainActivity=(MainActivity)context; 
        Intent intent=new Intent(context,SummaryCard.class); 
        intent.putExtra("Key", key); 
        intent.putExtra("access_token",mainActivity.getMyData()); 
        context.startActivity(intent); 
       } 
      } 
     }); 

這裏是我的活動

public class NotStartedMatchDetails extends AppCompatActivity { 

    Toolbar toolbar; 
    String str=""; 

    TextView txtA_team_name; 
    TextView txtB_team_name; 
    TextView txtDate; 
    TextView txtVanue; 
    TextView txtMatch_title; 
    Typeface tf; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_not_started_match_details); 

     toolbar=(Toolbar)findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
     tf=Typeface.createFromAsset(this.getResources().getAssets(), "Roboto-Regular.ttf"); 

     txtA_team_name=(TextView)findViewById(R.id.first_team_name); 
     txtB_team_name=(TextView)findViewById(R.id.second_team_name); 
     txtDate=(TextView)findViewById(R.id.date); 
     txtVanue=(TextView)findViewById(R.id.vanue); 

     txtA_team_name.setTypeface(tf,Typeface.BOLD); 
     txtB_team_name.setTypeface(tf,Typeface.BOLD); 
     txtDate.setTypeface(tf); 
     txtVanue.setTypeface(tf); 

     FrameLayout frameLayout=(FrameLayout)findViewById(R.id.adbar); 
     new AddLoader(this).LoadAds(frameLayout); 

     Bundle bundle=getIntent().getExtras(); 
     str=(String) bundle.get("mainobj"); 
     String key=(String)bundle.get("Key"); 

     Date date=null; 
     String ISTdateTime=""; 

     try{ 
      JSONObject mainObj=new JSONObject(str); 
      String name = mainObj.getString("name"); 
      String vanue=mainObj.getString("venue"); 
      String title=mainObj.getString("title"); 

      JSONObject start_date=mainObj.getJSONObject("start_date"); 
      String srt_date=start_date.getString("iso"); 

      try{ 
       DateFormat format=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'+00':ss"); 
       format.setTimeZone(TimeZone.getTimeZone("UTC")); 

       date=format.parse(srt_date); 

//    Sat Mar 19 19:30:00 GMT+05:30 2016 
       String[] name_parts; 
       String[] title_parts; 
       name_parts=name.split("vs"); 
       title_parts=title.split("-"); 

       ISTdateTime=date.toString(); 
       String[] ISTPARTS=ISTdateTime.split(" "); 
       String ISTdate=ISTPARTS[1]+" "+ISTPARTS[2]; 

       String ISTime=ISTPARTS[3]; 
       String[] Time_parts=ISTime.split(":"); 

       String hours=Time_parts[0]; 
       String minutes=Time_parts[1]; 

       String GMTDate=srt_date; 
       String[] GMT_parts=GMTDate.split("T"); 
       String gmt_time = GMT_parts[1]; 
       String[] gmt_hour_parts = gmt_time.split("\\+"); 
       String fullTime=ISTdate+","+hours+":"+minutes+" IST | "+gmt_hour_parts[0]+" GMT"; 

       txtA_team_name.setText(name_parts[0]); 
       txtB_team_name.setText(name_parts[1]); 
       txtDate.setText(fullTime); 
       txtVanue.setText(vanue); 
       getSupportActionBar().setTitle(title_parts[0]); 
      } 
      catch (Exception e){ 
       e.printStackTrace(); 
      } 
     } 
     catch (JSONException e){ 
      e.printStackTrace(); 
     } 
     try{ 
      SimpleDateFormat old_format =new SimpleDateFormat("HH:mm:ss"); 
      //oldDate.setTimeZone(TimeZone.getTimeZone("UTC")); 
      Date d1; 
      Date d2=null; 
//   Log.e("DAte",""+date.toString()); 
//   d1=oldDate.parse(oldDate.format(date)); 
//   Log.e("OLD DATE",""+d1.toString()); 

      d2=old_format.parse(old_format.format(new Date())); 
      Log.e("new date",""+d2.toString()); 

     } 
     catch (Exception e){ 
      e.printStackTrace(); 
     } 
    } 
    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()){ 
      case android.R.id.home: 
       Intent parentIntent = NavUtils.getParentActivityIntent(this); 
       parentIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
       startActivity(parentIntent); 
       finish(); 
       return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
} 

這裏是我的manifiest.xml文件

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.angelnx.cricvilla.cricvilla"> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/MyMaterialTheme"> 
     <activity 
      android:name=".SplashScreen" 
      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=".MainActivity" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait"></activity> 
     <activity 
      android:name=".NotStartedMatchDetails" 
      android:screenOrientation="portrait"> 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value=".MainActivity"></meta-data> 
     </activity> 
     <activity 
      android:name=".SummaryCard" 
      android:parentActivityName=".MainActivity" 
      android:screenOrientation="portrait" 
      android:theme="@style/MyMaterialTheme"> 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value=".MainActivity" /> 
     </activity> 
     <activity 
      android:name=".ScoreCard" 
      android:parentActivityName=".SummaryCard" 
      android:screenOrientation="portrait"> 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value=".SummaryCard" /> 
     </activity> 
     <activity 
      android:name=".PlayerInfoDetails" 
      android:parentActivityName=".MainActivity" 
      android:screenOrientation="portrait"> 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value=".MainActivity" /> 
     </activity> 
     <activity 
      android:name=".FullScore" 
      android:parentActivityName=".MainActivity" 
      android:screenOrientation="portrait"> 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value=".MainActivity" /> 
     </activity> 

     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 

     <activity android:name=".PlayerIccStats"></activity> 
    </application> 

</manifest> 

問題是當我按下我的活動的後退按鈕時,它直接轉而終止應用程序去homeFragment

請幫我解決這個問題。

+0

添加錯誤日誌.. –

+0

顯示您的清單文件 –

+0

它不會提供錯誤。 –

回答

1

您正在使用意圖的標誌在您的活動,使您的活動前,parentIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 爲什麼你的應用程序關閉這可能是這個原因,因爲現在你的活動是在最前,並有活動沒有更多的回棧剩下。

相關問題