Skip to content

Commit

Permalink
将super.onStart();移动到刷新操作之后再从多城市管理点击跳转就不崩溃了
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainHuangsh committed Jun 12, 2017
1 parent 50349f4 commit c67a664
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ private void toDeleteCity(final String cityStr) {
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

final SQLiteDatabase db = DBManager.getInstance().getDatabase();
db.delete("MultiCities", "city = ?", new String[]{
cityStr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected void onRestart() {

@Override
protected void onStart() {
super.onStart();

//从多城市管理界面跳转过来,并接收选中的城市编号
// Intent intent = this.getIntent();
// if (intent.getExtras().getString("city_num", "-1") != null) {
Expand Down Expand Up @@ -136,6 +136,7 @@ protected void onStart() {
}
cursor.close();
int mCityCount = (int) DBManager.getInstance().allCaseNum("MultiCities");
DBManager.getInstance().closeDatabase();
Log.d("WeatherMainhuang", " onStart count " + mCityCount);
if (mCityCount != 0) {
for (int i = 0; i < mCityCount; i++) {
Expand All @@ -151,7 +152,7 @@ protected void onStart() {
Log.d("WeatherMainhuang", "onStart getIntExtra " + cityNum);
}
mViewPager.setCurrentItem(cityNum + 1);
// }
super.onStart();//将super.onStart();移动到刷新操作之后再从多城市管理点击跳转就不崩溃了
}

/**
Expand Down Expand Up @@ -293,6 +294,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
cursor.close();
int mCityCount = (int) DBManager.getInstance().allCaseNum("MultiCities");
DBManager.getInstance().closeDatabase();
Log.d("WeatherMainhuang", " onActivityResult count " + mCityCount);
if (mCityCount != 0) {
for (int i = 0; i < mCityCount; i++) {
Expand Down Expand Up @@ -360,6 +362,7 @@ public void init() {
}
cursor.close();
int mCityCount = (int) DBManager.getInstance().allCaseNum("MultiCities");
DBManager.getInstance().closeDatabase();
if (mCityCount != 0) {
for (int i = 0; i < mCityCount; i++) {
// for (int i = 0; i < 2; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class MainFragment extends Fragment {
private boolean mIsCreateView = false;
private WeatherMain mActivity;
private Weather mWeather;
private int mToastSuccess;
private int times = 0;

private Handler mHandler = new Handler() {
Expand Down Expand Up @@ -132,6 +133,7 @@ public void run() {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mToastSuccess = 0;
}

@Override
Expand Down Expand Up @@ -259,6 +261,7 @@ public void initRecycleView() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onRefresh() {
mToastSuccess = 0;
refresh();
}
});
Expand Down Expand Up @@ -311,7 +314,9 @@ public void getWeather() {
mNoData.setVisibility(View.VISIBLE);
// Toast.makeText(getActivity(), " 定位失败,请手动输入城市", Toast.LENGTH_LONG).show();
}
Toast.makeText(getActivity(), "加载完毕,✺◟(∗❛ัᴗ❛ั∗)◞✺,", Toast.LENGTH_SHORT).show();
if (mToastSuccess == 0)
Toast.makeText(getActivity(), "加载完毕,✺◟(∗❛ัᴗ❛ั∗)◞✺,", Toast.LENGTH_SHORT).show();
mToastSuccess++;
}

public void safeSetTitle(String title) {
Expand Down

0 comments on commit c67a664

Please sign in to comment.