1. Download our Official Android App: Forums for Android!

Apps Toast not displaying text and Manifest.XML error and AVDs timed out !

Discussion in 'Android Development' started by ac4android, Jun 30, 2016.

  1. ac4android

    ac4android Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    53
    Posts:
    198
    Joined:
    Nov 3, 2015

    Nov 3, 2015
    198
    29
    53
    Hi. I use Toast.makeText a lot to help me debug, but recently it has stopped displaying text on my Android 5 Samsung S5.

    Meanwhile, AndroidManifest.XML throws a "...is not assignable to 'android.app.activity' and 'Validates resoruce references inside Android XML files'.

    I don't mind that all the AVDs have stopped working with a "300 seconds timed out waiting for emulator" issue since I am relying on my Android Smartphone.

    Can someone help with the toast display issue ?

    I also need to know how to fix the AndroidManifest.XML error

    Here is the Manifest
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    4.     package="com.myexamples.testgpsservice">
    5.  
    6.     <application
    7.         android:allowBackup="true"
    8.         android:icon="@mipmap/ic_launcher"
    9.         android:label="@string/app_name"
    10.         android:supportsRtl="true"
    11.         android:theme="@style/AppTheme">
    12.         <activity
    13.             android:name=".MainActivity"
    14.             android:label="@string/app_name"
    15.             android:theme="@style/AppTheme.NoActionBar">
    16.             <intent-filter>
    17.                 <action android:name="android.intent.action.MAIN" />
    18.  
    19.                 <category android:name="android.intent.category.LAUNCHER" />
    20.             </intent-filter>
    21.         </activity>
    22.         <activity android:name=".MyGpsService"></activity>      <======= ERROR here, .MyGpsService is not assignable to android.app.activity
    23.     </application>
    24.  
    25. </manifest>
    26.  
    Here is the content_main.xml
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.     xmlns:app="http://schemas.android.com/apk/res-auto"
    5.     xmlns:tools="http://schemas.android.com/tools"
    6.     android:layout_width="match_parent"
    7.     android:layout_height="match_parent"
    8.     android:paddingBottom="@dimen/activity_vertical_margin"
    9.     android:paddingLeft="@dimen/activity_horizontal_margin"
    10.     android:paddingRight="@dimen/activity_horizontal_margin"
    11.     android:paddingTop="@dimen/activity_vertical_margin"
    12.     app:layout_behavior="@string/appbar_scrolling_view_behavior"
    13.     tools:context="com.myexamples.testgpsservice.MainActivity"
    14.     tools:showIn="@layout/activity_main">
    15.  
    16.  
    17.     <TextView
    18.         android:id="@+id/textView1"
    19.         android:layout_width="wrap_content"
    20.         android:layout_height="wrap_content"
    21.         android:text="About Android Services"
    22.         android:layout_alignParentTop="true"
    23.         android:layout_centerHorizontal="true"
    24.         android:textSize="25dp" />
    25.  
    26.     <TextView
    27.         android:id="@+id/textView2"
    28.         android:layout_width="wrap_content"
    29.         android:layout_height="wrap_content"
    30.         android:text="How to start and stop servics!"
    31.         android:textColor="@color/colorPrimaryDark"
    32.         android:textSize="20dp"
    33.         android:layout_below="@+id/textView1"
    34.         android:layout_centerHorizontal="true"
    35.         android:layout_marginBottom="40dp" />
    36.  
    37.    <LinearLayout
    38.         android:layout_width="match_parent"
    39.         android:layout_height="match_parent"
    40.         android:layout_marginTop="150dp"
    41.         android:orientation="horizontal">
    42.  
    43.         <Button
    44.             android:id="@+id/button"
    45.             style="?android:attr/buttonStyleSmall"
    46.             android:layout_width="0dp"
    47.             android:layout_height="wrap_content"
    48.             android:layout_weight="1"
    49.             android:text="Start Services"
    50.             android:onClick="startService"
    51.             android:layout_below="@+id/textView2"/>
    52.  
    53.         <Button
    54.             android:id="@+id/button2"
    55.             style="?android:attr/buttonStyleSmall"
    56.             android:layout_width="0dp"
    57.             android:layout_height="wrap_content"
    58.             android:layout_weight="1"
    59.             android:text="Stop Services"
    60.             android:onClick="stopService"
    61.             android:layout_below="@+id/textView2"
    62.             android:layout_centerHorizontal="true"/>
    63.    </LinearLayout>
    64.  
    65. </RelativeLayout>
    66.  
    67.  
    Here is MainActivity.java
    Code (Text):
    1.  
    2. import android.os.Bundle;
    3. import android.app.Activity;
    4. import android.view.Menu;
    5. import android.content.Intent;
    6. import android.view.View;
    7.  
    8. public class MainActivity extends Activity {
    9.  
    10.     @Override
    11.     public void onCreate(Bundle savedInstanceState) {
    12.         super.onCreate(savedInstanceState);
    13.         setContentView(R.layout.activity_main);
    14.     }
    15.  
    16.     @Override
    17.     public boolean onCreateOptionsMenu(Menu menu) {
    18.         getMenuInflater().inflate(R.menu.menu_main, menu);
    19.         return true;
    20.     }
    21.  
    22.     // Method to start the service
    23.     public void startService(View view) {
    24.         startService(new Intent(getBaseContext(), MyGpsService.class));
    25.     }
    26.  
    27.     // Method to stop the service
    28.     public void stopService(View view) {
    29.         stopService(new Intent(getBaseContext(), MyGpsService.class));
    30.     }
    31. }
    32.  
    Here is the MyGpService.java class
    Code (Text):
    1.  
    2.  
    3. import android.app.Service;
    4. import android.content.Intent;
    5. import android.os.IBinder;
    6. import android.widget.Toast;
    7.  
    8. public class MyGpsService extends Service {
    9.  
    10.     @Override
    11.     public IBinder onBind(Intent arg0) {
    12.         return null;
    13.     }
    14.  
    15.     @Override
    16.     public int onStartCommand(Intent intent, int flags, int startId) {
    17.         // TODO start locationListener here
    18.         Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
    19.         return START_STICKY;
    20.     }
    21.  
    22.     @Override
    23.     public void onDestroy() {
    24.         // TODO make sure the service is stopped, else it continues running
    25.         super.onDestroy();
    26.         Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
    27.     }
    28. }
    29.  


    And here is the activity_my_gs_service.xml ( it is not actually used, but I left it there in case that's the cause of the problem in the Manifest
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.     xmlns:tools="http://schemas.android.com/tools"
    5.     android:layout_width="match_parent"
    6.     android:layout_height="match_parent"
    7.     android:paddingBottom="@dimen/activity_vertical_margin"
    8.     android:paddingLeft="@dimen/activity_horizontal_margin"
    9.     android:paddingRight="@dimen/activity_horizontal_margin"
    10.     android:paddingTop="@dimen/activity_vertical_margin"
    11.     tools:context="com.myexamples.testgpsservice.MyGpsService">
    12.  
    13. </RelativeLayout>
    14.  
    15.  
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #17
    Points:
    1,488
    Posts:
    6,729
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    6,729
    9,485
    1,488
    Male
    Software developer
    South West of England
    Your problem is because class MyGpsService doesn't extend Activity.
    It's a Service, you can't use it as an Activity in your manifest.
     
    ac4android likes this.
  3. ac4android

    ac4android Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    53
    Posts:
    198
    Joined:
    Nov 3, 2015

    Nov 3, 2015
    198
    29
    53

    It was inserted by A/S automagically. So we just delete it from Manifest?

    Also, any idea on Toast?

    I'll reinstall A/S today to see if it solves some of the problems.


    P.S. Ahh, I see, I need a Handler to hand the Toast message to the Activity.

    What is the difference between Service and IntentService ?
     
    #3 ac4android, Jul 1, 2016
    Last edited: Jul 1, 2016
  4. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #17
    Points:
    1,488
    Posts:
    6,729
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    6,729
    9,485
    1,488
    Male
    Software developer
    South West of England

Share This Page

Loading...