2016-03-22 2 views
0

Объяснение: У меня есть навигационный ящик, в котором имеется несколько fragments.Like HomeFragment, firstFragment, secondFragment и т.д. В 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); Возможно, это причина, по которой ваше приложение закрывается, потому что теперь ваша деятельность находится в самом начале и больше нет стоп-операций оставил.

Смежные вопросы