0

here Dev guideからAndroidアクティビティのライフサイクルについて読みました。onCreate、onStart、onResume、onRestart、onPause、onResume、onStop、onDestroy など、コードのどの部分がどのメソッドに存在するかについて混乱しています。それらを適切な場所に配置するのを手伝ってくれませんか。また、アプリケーションが最小化されている場合でも、追跡は継続する必要があります。次のコードがあります。

public class MainActivity extends FragmentActivity implements  LocationListener {

//List of user defined variables

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    /*for now i  have kept everything in onCreate method
     * i have start and stop button to start the tracking and stop the tracking and show the distance of travel
    1. Checking whether GPS is on or OFF
    2. button = (ImageButton) findViewById(R.id.myButton);
    3. Code to load the Google map
    4. Now specified what start and stop button does.
        i. when i press start button it starts overlaying the path in the map and calculate distance travelled so far
        ii. when i press stop button it stops tracking and shows the details of final result in next activity.
    LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 2, this);
    */

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

@Override
public void onLocationChanged(Location arg0) {
    // TODO Auto-generated method stub
    //i hace code for tracking and overlaying here

}

@Override
public void onProviderDisabled(String arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
    // TODO Auto-generated method stub

}

}

4

1 に答える 1

1

「記録開始ボタンと記録停止ボタンがあり、その間にGoogleマップを使用してルートを表示するアプリ」というアイデアに基づいています。正しい?

次の 2 つのコンポーネントが必要です。

サービス(バックグラウンド オペレーション)

  • 開始時: GPS の更新をリッスンし、内部に保存します。
  • 停止時: 聞くのをやめる

アクティビティ(GUI)

2 つのボタン、録画の開始と停止、および Google マップ ウィジェットがあります。

  • ボタンで開始: を使用startServiceして開始しますService
  • ボタンで停止: を使用stopServiceして停止します。Service
  • 場所の取得 (onResumeとの間onPause): 内部的に保存された場所について (バインディングまたはメッセージャーを使用して) サービスに問い合わせます。取得したら、Google マップのウィジェットで表示します。
于 2013-09-27T14:21:14.390 に答える