Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7436361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:13:39+00:00 2026-05-29T10:13:39+00:00

I have a class named MyPrimaryClass, this class has a button witch when pressed,

  • 0

I have a class named MyPrimaryClass, this class has a button witch when pressed, creates an Intent with the class myClassForResult.

I use this to start it:

startActivityForResult(myIntentOfMyClassForResult, ACTIVITY_EDIT_BTEXT);

Both MyPrimaryClass, and myClassForResult extends Activity.

So, when I call Toast.makeText within the myClassForResult, with the text parameter of R.string.my_resource_string, it gives me Force Close!

I have tried this:

Context c = myClassForResult.this;
Toast toast = Toast.makeText(c,
    c.getResources().getString(R.string.my_resource_string),
    Toast.LENGTH_SHORT);
toast.show();

Also this: c = getApplicationContext()

Also this: c = getBaseContext()

Also this:

Context c = MyPrimaryClass.this;
Toast toast = Toast.makeText(c,
    R.string.my_resource_string,
    Toast.LENGTH_SHORT);
toast.show();

If I use an inline string, like “My toast Text!”, it works. But i need to get a string from the resources.

-Problem solved:

To solve the problem I changed the duration of the Toast to Toast.LENGTH_LONG

The string R.string.my_resource_string value is “The title is empty”

When I change its value to “The title”, it worked properly, so I guess the string was too long for the Toast.LENGTH_SHORT duration.

But when i change the duration to Toast.LENGTH_LONG, I could use the long string.

Context c = MyPrimaryClass.this;
Toast toast = Toast.makeText(c,
    R.string.my_resource_string,
    Toast.LENGTH_LONG);
toast.show();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:13:39+00:00Added an answer on May 29, 2026 at 10:13 am

    One thing to note:

    Toast toast = Toast.makeText(c,
        c.getResources().getString(R.string.my_resource_string),
        Toast.LENGTH_SHORT);
    toast.show();
    

    Can be simplified into:

    Toast.makeText(c,
        c.getResources().getString(R.string.my_resource_string),
        Toast.LENGTH_SHORT).show();
    

    This saves you an object reference that you do not need.

    One thing you need to understand is that whenever you reference you R in your package (not android.R.) you will have access to your resources as long as you have Context.

    Update

    After realizing what you are using this for I would recommend that you
    change your approach
    , while this is in fact possible, your approach isn’t ideal for something so simple.

    The method startActivityForResult(xx) is typically when you want to start an application that is outside of your package for a result.

    For instance: if I wanted to retrieve a barcode from a product, then I’d start an Intent to that barcode class, indirectly through an action. Then I’d retrieve the data through using onActivityResult(xx).

    it makes No Sense to do this for your own classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class named myClass. This class has TouchesMoved and TouchesBegan defined. This
I have a class named baseClass. From this class I inherit a class names
I have a class named Person and in this class is the property PersonName
I have a class named InvoiceLine which has the following properties. public class InvoiceLine
I have a class named Graph, in this class I have a member named
I have a class named Entry declared like this: class Entry{ string Id {get;set;}
I have a class named WhatClass that has List field in it. I need
I have an class named Foo. This class contains a collection of child objects
I have a class named Particle which has a std::set as a member. The
I have a class named MyClass. And in the file MyClass.m I start the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.