• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

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

ac4android

Well-Known Member
Nov 3, 2015
198
29
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:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myexamples.testgpsservice">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MyGpsService"></activity>      <======= ERROR here, .MyGpsService is not assignable to android.app.activity
    </application>

</manifest>

Here is the content_main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.myexamples.testgpsservice.MainActivity"
    tools:showIn="@layout/activity_main">


    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="About Android Services"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textSize="25dp" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="How to start and stop servics!"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="20dp"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="40dp" />

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="150dp"
        android:orientation="horizontal">

        <Button
            android:id="@+id/button"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Start Services"
            android:onClick="startService"
            android:layout_below="@+id/textView2"/>

        <Button
            android:id="@+id/button2"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Stop Services"
            android:onClick="stopService"
            android:layout_below="@+id/textView2"
            android:layout_centerHorizontal="true"/>
   </LinearLayout>

</RelativeLayout>

Here is MainActivity.java
Code:
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    // Method to start the service
    public void startService(View view) {
        startService(new Intent(getBaseContext(), MyGpsService.class));
    }

    // Method to stop the service
    public void stopService(View view) {
        stopService(new Intent(getBaseContext(), MyGpsService.class));
    }
}

Here is the MyGpService.java class
Code:
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;

public class MyGpsService extends Service {

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // TODO start locationListener here
        Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        // TODO make sure the service is stopped, else it continues running
        super.onDestroy();
        Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
    }
}



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:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.myexamples.testgpsservice.MyGpsService">

</RelativeLayout>
 
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.


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 ?
 
Last edited:
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones