Code works great. However, I am seeing something strange from an Activity Lifecycle perspective. The onCreate code basically sets the adapters to the relevant GridView and pulls items from a database and populates said GridView. Each item can be tapped by the user that will push the item's "playerId" to HubActivity.

The below is my onCreate code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Const.err("##> Running PlayerSearchActivity.onCreate");
    setContentView(R.layout.activity_playersearch);
    this.mPlayerSearchBtn=(Button) findViewById(R.id.playerSearchButton);
    this.mPlayerSearchText=(TextView) findViewById(R.id.playerSearchText);
    this.mPlayerSearchGridView=(GridView) findViewById(R.id.psearch_playersearchgrid);
    this.mSavedPlayersGridView=(GridView) findViewById(R.id.psearch_savedplayersgrid);
    mPlayerSearchBtn.setOnClickListener(this);

    this.savedPlayersAdapter = new PlayerGridAdapter(this);
    mSavedPlayersGridView.setAdapter(savedPlayersAdapter);
    mSavedPlayersGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position,long arg3) {
            Intent intent = new Intent(getApplicationContext(), HubActivity.class);
            intent.putExtra(Keys._PLAYERID,savedPlayersAdapter.getItemPlayerId(position));
            startActivity(intent);
        }
    });

    Const.err("<## Completed PlayerSearchActivity.onCreate");

}

I was curious about how each method was being called so I applied some logging around the functions (Const.err). The results are strange:

03-04 00:29:50.942:  ##> Running PlayerSearchActivity.onCreate
03-04 00:29:50.982:  <## Completed PlayerSearchActivity.onCreate
03-04 00:29:50.982:  ##> Running PlayerSearchActivity.onResume
03-04 00:29:51.058:  <## Completed PlayerSearchActivity.onResume

---Clicked item---

03-04 00:29:54.718:  ##> Running PlayerSearchActivity.onCreate
03-04 00:29:54.730:  <## Completed HubActivity.onCreate
..

Firstly, why is onCreate being called after I click an item? Also, I expected to see a "Completed PlayerSearchActivity.onCreate" message but this never occurrs.

没有正确的解决方案

其他提示

I guess this is a copy-paste error, check your HubActivity.onCreate(), if you didn't paste by accident

Const.err("##> Running PlayerSearchActivity.onCreate");

instead of

Const.err("##> Running HubActivity.onCreate");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top