1. Nimm jetzt an unserem Uhans - 3. ADVENT - Gewinnspiel teil - Alle Informationen findest Du hier!

5 Tab Activitys und ein Service. Probleme (source code Problem)

Dieses Thema im Forum "Android App Entwicklung" wurde erstellt von KianS, 04.10.2010.

  1. KianS, 04.10.2010 #1
    KianS

    KianS Threadstarter Neuer Benutzer

    Beiträge:
    7
    Erhaltene Danke:
    0
    Registriert seit:
    06.09.2010
    Hi zusammen.

    ich habe 5 Tabs erstellt (Maintab,StatusTab,NetgpsTab,LogTab,SettingTab)
    , die als alleiniges Projekt wunderbar funktionieren.

    Desweiteren habe ich eine Activity ( die ich hier in diesem Beispiel in NetgpsTab kopiert habe) und ein Service ( myservice, welches wunderbar funktioniert) , welches auch als allein Projekt super funktionieren.


    Wenn ich nun alles zusammenfügen will, bekomme ich die Ganze Zeit Fehler :-(
    und ein absturz.....


    was haben wir




    kann da mal einer reingucken ...

    Manifest
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="QC.Package"
    android:versionCode="1"
    android:versionName="1.0">
    
    <application android:icon="@drawable/ic_tab_main" android:label="@string/app_name">
    
    <activity android:name=".QC_MainActivity"
    android:label="@string/app_name">
    
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    
    <activity android:name=".MainTab">
     <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
    </activity>
         
    <activity android:name=".StatusTab"
    
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    </activity>
    
    <activity android:name=".NetGpsTab"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    <service android:enabled="true" android:name=".MyService" />
    </activity>
    
    <activity android:name=".LogsTab"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    </activity>
    
    
    
    <activity android:name=".SettingsTab"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    </activity>
    
    
    
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    
    
    
    
    </application>
    <uses-sdk android:minSdkVersion="7"></uses-sdk>
    
    </manifest> 
    layout netgps
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center">
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" android:gravity="center" android:textSize="20sp" android:padding="20dp" android:text="Services Demo "/>
    <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/buttonStart" android:text="Start"></Button>
    <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Stop" android:id="@+id/buttonStop"></Button>
    </LinearLayout>
    

    layout main
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">  
    </TabHost>
    MainActivitiy
    Code:
    package QC.Package;
    
    import android.app.TabActivity;
    import android.content.Intent;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.widget.TabHost;
    
    
    
    public class QC_MainActivity extends TabActivity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Resources res = getResources(); // Resource object to get 
            TabHost tabHost = getTabHost();  // The activity TabHost
            TabHost.TabSpec spec;  // TabSpec for each tab
            Intent intent;  // Reusable Intent for each tab
    
            // Create an Intent to launch an Activity for the tab (to be reused)
            intent = new Intent().setClass(this, MainTab.class);
    
            // Initialize a TabSpec for each tab and add it to the TabHost
            spec = tabHost.newTabSpec("Main").setIndicator("Main",
                              res.getDrawable(R.drawable.ic_tab_main))
                          .setContent(intent);
            tabHost.addTab(spec);
    
          
            
            intent = new Intent().setClass(this, StatusTab.class);
            spec = tabHost.newTabSpec("Status").setIndicator("Status",
                              res.getDrawable(R.drawable.ic_tab_status))
                          .setContent(intent);
            tabHost.addTab(spec);
    
            intent = new Intent().setClass(this, NetGpsTab.class);
            spec = tabHost.newTabSpec("NetGps").setIndicator("NetGps",
                              res.getDrawable(R.drawable.ic_tab_netgps))
                          .setContent(intent);
            tabHost.addTab(spec);
            
            intent = new Intent().setClass(this, LogsTab.class);
            spec = tabHost.newTabSpec("Logs").setIndicator("Logs",
                              res.getDrawable(R.drawable.ic_tab_logs))
                          .setContent(intent);
            tabHost.addTab(spec);  
            
            intent = new Intent().setClass(this, SettingsTab.class);
            spec = tabHost.newTabSpec("Settings").setIndicator("Settings",
                              res.getDrawable(R.drawable.ic_tab_settings))
                          .setContent(intent);
            tabHost.addTab(spec);
    
            tabHost.setCurrentTab(0);      
    	}
    }
    NetGpsTab
    Code:
    package QC.Package;
    
    import QC.Package.MyService;
    import QC.Package.R;
    import android.app.Activity;
    import android.os.Bundle;
    import android.content.Intent;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    
    
    public class NetGpsTab extends Activity implements OnClickListener {
      private static final String TAG = "NetGpsTab";
      Button buttonStart, buttonStop;
    
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.netgps);
    
        buttonStart = (Button) findViewById(R.id.buttonStart);
        buttonStop = (Button) findViewById(R.id.buttonStop);
    
        buttonStart.setOnClickListener(this);
        buttonStop.setOnClickListener(this);
      }
    
      public void onClick(View src) {
        switch (src.getId()) {
        case R.id.buttonStart:
          Log.d(TAG, "onClick: starting srvice");
          startService(new Intent(this, MyService.class));
          break;
        case R.id.buttonStop:
          Log.d(TAG, "onClick: stopping srvice");
          stopService(new Intent(this, MyService.class));
          break;
        }
      }
      
    }
    Maintab
    Code:
    package QC.Package;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.TextView;
    
    public class MainTab extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            TextView textview = new TextView(this);
            textview.setText("This is the Main tab");
            setContentView(textview);
        }
    }
     

    Anhänge:

  2. MetBo, 04.10.2010 #2
    MetBo

    MetBo Fortgeschrittenes Mitglied

    Beiträge:
    264
    Erhaltene Danke:
    4
    Registriert seit:
    14.05.2010
    Fehler, bzw. Logcat Log ?
     
  3. KianS, 04.10.2010 #3
    KianS

    KianS Threadstarter Neuer Benutzer

    Beiträge:
    7
    Erhaltene Danke:
    0
    Registriert seit:
    06.09.2010
    [2010-10-04 19:03:00 - QC_Service_Analyser] ------------------------------
    [2010-10-04 19:03:00 - QC_Service_Analyser] Android Launch!
    [2010-10-04 19:03:00 - QC_Service_Analyser] adb is running normally.
    [2010-10-04 19:03:00 - QC_Service_Analyser] Performing QC.Package.QC_MainActivity activity launch
    [2010-10-04 19:03:00 - QC_Service_Analyser] Automatic Target Mode: Unable to detect device compatibility. Please select a target device.
    [2010-10-04 19:03:03 - QC_Service_Analyser] Application already deployed. No need to reinstall.
    [2010-10-04 19:03:03 - QC_Service_Analyser] Starting activity QC.Package.QC_MainActivity on device
    [2010-10-04 19:03:03 - QC_Service_Analyser] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=QC.Package/.QC_MainActivity }
    [2010-10-04 19:03:21 - QC_Service_Analyser] ------------------------------
    [2010-10-04 19:03:21 - QC_Service_Analyser] Android Launch!
    [2010-10-04 19:03:21 - QC_Service_Analyser] adb is running normally.
    [2010-10-04 19:03:21 - QC_Service_Analyser] Performing QC.Package.QC_MainActivity activity launch
    [2010-10-04 19:03:21 - QC_Service_Analyser] Automatic Target Mode: Unable to detect device compatibility. Please select a target device.
    [2010-10-04 19:03:23 - QC_Service_Analyser] Application already deployed. No need to reinstall.
    [2010-10-04 19:03:23 - QC_Service_Analyser] Starting activity QC.Package.QC_MainActivity on device
    [2010-10-04 19:03:23 - QC_Service_Analyser] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=QC.Package/.QC_MainActivity }



    10-04 19:03:08.074: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:09.075: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:10.074: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:10.744: INFO/BatteryStatsImpl(93): notePhoneSignalStrengthLocked: 2->3
    10-04 19:03:11.074: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:12.075: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:13.076: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:14.075: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:14.734: DEBUG/AndroidRuntime(13700): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
    10-04 19:03:14.734: DEBUG/AndroidRuntime(13700): CheckJNI is OFF
    10-04 19:03:14.734: DEBUG/dalvikvm(13700): creating instr width table
    10-04 19:03:14.774: DEBUG/AndroidRuntime(13700): --- registering native functions ---
    10-04 19:03:14.954: DEBUG/AndroidRuntime(13700): Shutting down VM
    10-04 19:03:14.964: DEBUG/dalvikvm(13700): Debugger has detached; object registry had 1 entries
    10-04 19:03:14.964: INFO/AndroidRuntime(13700): NOTE: attach of thread 'Binder Thread #3' failed
    10-04 19:03:15.074: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:15.084: DEBUG/AndroidRuntime(13709): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
    10-04 19:03:15.084: DEBUG/AndroidRuntime(13709): CheckJNI is OFF
    10-04 19:03:15.084: DEBUG/dalvikvm(13709): creating instr width table
    10-04 19:03:15.114: DEBUG/AndroidRuntime(13709): --- registering native functions ---
    10-04 19:03:15.314: INFO/ActivityManager(93): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=QC.Package/.QC_MainActivity }
    10-04 19:03:15.354: DEBUG/AndroidRuntime(13709): Shutting down VM
    10-04 19:03:15.354: DEBUG/AK8973(73): Compass Start
    10-04 19:03:15.354: DEBUG/Sensors(93): open_akm, fd=128
    10-04 19:03:15.364: DEBUG/jdwp(13709): Got wake-up signal, bailing out of select
    10-04 19:03:15.364: DEBUG/dalvikvm(13709): Debugger has detached; object registry had 1 entries
    10-04 19:03:15.374: DEBUG/dalvikvm(13709): Compiler shutdown in progress - discarding request
    10-04 19:03:15.374: DEBUG/dalvikvm(13709): Compiler shutdown in progress - discarding request
    10-04 19:03:15.374: DEBUG/dalvikvm(13709): Compiler shutdown in progress - discarding request
    10-04 19:03:15.374: DEBUG/dalvikvm(13709): Compiler shutdown in progress - discarding request
    10-04 19:03:16.077: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:17.076: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:18.077: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:19.077: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:20.077: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:21.078: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:21.214: INFO/power(93): *** set_screen_state 0
    10-04 19:03:21.244: VERBOSE/KeyguardViewMediator(93): password timeout delay 240042ms
    10-04 19:03:21.244: DEBUG/KeyguardViewManager(93): show()
    10-04 19:03:21.264: DEBUG/Sensors(93): close_akm, fd=128
    10-04 19:03:21.284: DEBUG/HtcLockScreen(93): onScreenRestart
    10-04 19:03:21.284: INFO/HtcLockScreen(93): updateStatusViewByPriority, mIsSimCheckView = false, mIsBatteryInfo = false, mIsMusicPlaying = false, mIsAirPlaneMode = false
    10-04 19:03:21.284: INFO/HtcLockScreen(93): HtcLockScreen:onResume
    10-04 19:03:21.284: DEBUG/StatusBar(93): DISABLE_EXPAND: yes
    10-04 19:03:21.384: DEBUG/ConnectivityService(93): getMobileDataEnabled returning true
    10-04 19:03:21.394: DEBUG/ConnectivityService(93): getMobileDataEnabled returning true
    10-04 19:03:21.404: DEBUG/ConnectivityService(93): getMobileDataEnabled returning true
    10-04 19:03:21.414: DEBUG/browser(8250): screen intent received: android.intent.action.SCREEN_OFF
    10-04 19:03:21.414: DEBUG/browser(8250): mActivityInPause=true toggleAutorestart=true
    10-04 19:03:21.414: DEBUG/browser(8250): restartFlag=false restartPowerLock=WakeLock{460c9f58 held=false, refCount=0}
    10-04 19:03:21.424: DEBUG/EAS_AppSvc(448): 06021143 setScreenOn(false)
    10-04 19:03:21.424: DEBUG/MailSyncSource(448): 06021143 setScreenOn(false)
    10-04 19:03:21.434: DEBUG/EAS_AppSvc(448): 06021143 isWifiNetwork: false
    10-04 19:03:21.554: DEBUG/SurfaceFlinger(93): About to give-up screen, flinger = 0x157ff0
    10-04 19:03:21.574: DEBUG/AK8973(73): Compass CLOSE
    10-04 19:03:21.795: WARN/ActivityManager(93): Activity pause timeout for HistoryRecord{464d0ae0 QC.Package/.QC_MainActivity}
    10-04 19:03:22.077: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:23.078: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:24.079: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:25.078: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:25.369: WARN/ActivityManager(93): Activity idle timeout for HistoryRecord{464d0ae0 QC.Package/.QC_MainActivity}
    10-04 19:03:26.078: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:26.425: VERBOSE/AlarmManager(93): Adding Alarm{466302f8 type 2 com.android.browser} Jan. 03 08:24:10 vorm.
    10-04 19:03:27.079: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:28.079: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:29.079: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:30.080: INFO/Task(11288): Incrementing counter in the run method
    10-04 19:03:30.454: DEBUG/dalvikvm(200): GC_EXPLICIT freed 11709 objects / 644968 bytes in 86ms
    10-04 19:03:31.081: INFO/Task(11288): Incrementing counter in the run method




    Ich bekomme auf dem Handy eine Fehlermeldung :

    tut uns leid, die Anwendung ... wurde unerwartet beendet
     
  4. KianS, 06.10.2010 #4
    KianS

    KianS Threadstarter Neuer Benutzer

    Beiträge:
    7
    Erhaltene Danke:
    0
    Registriert seit:
    06.09.2010
    keiner da der mal helfen kann ?
     
  5. FelixL, 06.10.2010 #5
    FelixL

    FelixL Ehrenmitglied

    Beiträge:
    4,855
    Erhaltene Danke:
    754
    Registriert seit:
    26.11.2009
    Phone:
    Wileyfox Swift, HTC One M8
    10-04 19:03:21.795: WARN/ActivityManager(93): Activity pause timeout for HistoryRecord{464d0ae0 QC.Package/.QC_MainActivity}

    ANR weil du zu langsam bist.
    Was auch immer du machst das zu lange dauert, lager es in einen Thread aus oder mach es schneller.
    Hab mir deinen Code aber nicht angesehen und kann auch ganz falsch liegen :D


    Edit: Okay, vergiss es, liege wahrscheinlich falsch.
     
    Zuletzt bearbeitet: 06.10.2010
  6. swordi, 06.10.2010 #6
    swordi

    swordi Gewerbliches Mitglied

    Beiträge:
    3,389
    Erhaltene Danke:
    441
    Registriert seit:
    09.05.2009
    sowas ist keine fehlermeldung ( zumindest nicht im developer bereich )
     

Diese Seite empfehlen