So I was following this tutorial and got everything mostly working. But for some reason, the line that says initialize() is not being recognized by Android Studio.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.part_camera_view);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
myContext = this;
initialize(); //This line is not recognized
}
I'm way too new to understanding what's going on, so I'm hoping to be nudged in the right direction. I can't find anything in Android documents that talk about initialize()
I've basically copy and pasted the script from the tutorial and changed the specific elements to fit my project. I am able to see a screen with the buttons provided, but I can not see the live view from the camera, and I believe that line is the problem
Any thoughts?
Initialize is a function. It isn't a prebuilt SDK function- if you want one, you have to write it yourself. If you don't need one, the call to it shouldn't be there.
As an aside, I have serious concerns about this code without even looking at the link to the tutorial- there's no reason to store this in a separate variable, and it makes me doubt the author understands his own code.
If you scroll down to the bottom of the tutorials page you will find a link where you can download the source code of the example project. You will find the initialize method in theAndroidCameraExample class.
Related
So I'm still fairly new to Android Studio and programming in general and I'm trying to follow this course by Udacity. The problem is that in MainActivity.java all it says in mine is
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ...
}
while they have more Override Methods such as OnOptionsItemSelected, etc. I believe I was told by them to set it to "Blank Activity", which I believe is "Empty Activity" now, and I think the problem is the updates that have been made since there video had been made and now, but I'm just looking for a solution for this. Any help would be appreciated. I hope I am making sense here Thanks.
What you're looking for is "Basic Activity" instead of "Empty Activity" and you should be able to continue following the tutorial.
If they have the xml files and java files available, once you copy and paste it should look the same as well.
Sounds like you didn't really know about Android's coding framework, and need to read some example or tutorial.
I'm not have any relation about the following site, but as my point of view, it's a good Android coding tutorial.
Android - Hello World Example
OnOptionItemSelected is a callback method which handles menus.
You only need the onCreate callback method in order to display a sample Hello world! and then follow the Udacity course.
You can erase the others if you have created a blank activity instead of an empty one.
I'm programming an app using android studio. I want to know in which way I can do a tutorial that users will see only the first time that use the app. Tutorial like image or screenshoots
Can someone help me? Thanks
I encountered this thread while looking for a solution for running a tutorial only at the first time (as rbaleksandar suggested), so in case it will be helpful for someone someday, here's a template of a solution that works for me (using the SharedPreferences API):
#Override
protected void onResume() {
super.onResume();
String tutorialKey = "SOME_KEY";
Boolean firstTime = getPreferences(MODE_PRIVATE).getBoolean(tutorialKey, true);
if (firstTime) {
runTutorial(); // here you do what you want to do - an activity tutorial in my case
getPreferences(MODE_PRIVATE).edit().putBoolean(tutorialKey, false).apply();
}
}
EDIT - BONUS - If you're into app tutorial - I'm messing now with the ShowcaseView library (which is amazing - try it out). Apparently they have some shortcut for that issue using a method called singleShot(long) - its input is a key for the SharedPreferences, and it does the exact same thing - runs only in the first activation. Example of usage (taken from here):
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_shot);
Target viewTarget = new ViewTarget(R.id.button, this);
new ShowcaseView.Builder(this)
.setTarget(viewTarget)
.setContentTitle(R.string.title_single_shot)
.setContentText(R.string.R_string_desc_single_shot)
.singleShot(42)
.build();
}
You could always code your own solution, but, let us not reinvent the wheel.
Check this Android Library:
Tour Guide Repository
It allows you to add pointers in your screen, so the user knows where is he supposed to touch next.
It's pretty easy to use, you only need to point to the element you want the user to touch.
From the doc:
Let's say you have a button like this where you want user to click on:
Button button = (Button)findViewById(R.id.button);
You can add the tutorial pointer on top of it by:
TourGuide mTourGuideHandler = TourGuide.init(this).with(TourGuide.Technique.Click)
.setPointer(new Pointer())
.setToolTip(new ToolTip().setTitle("Welcome!").setDescription("Click on Get Started to begin..."))
.setOverlay(new Overlay())
.playOn(button);
Hope this helps!
Some links to libraries for creating introduction and/or tutorial screens.
Horizontal cards like Google Now:
https://github.com/PaoloRotolo/AppIntro
Tutorial screen:
https://github.com/amlcurran/ShowcaseView
As far as I understand the question is not How do I create a tutorial? (as the people who have already posted an answer have concluded) but instead How to show a tutorial upon first launch only?. So here are my two cents on this topic:
I'm not familiar with how your Android app stores its configuration data but I will assume that it's either in a database (SQLite) or a text file (plaintext, YAML, XML - whatever). Add a configuration entry to wherever the app's settings are being stored - something like tutorial_on : false, tutorial_on : 1 etc. depending on the format the configuration is represented in.
The way configurations work is that whenever an app (or software in general) is launched it has to be loaded in the app itself. So add the following to your app (where and how is up to you and your app design):
Check tutorial_on entry
If tutorial_on is set to true/1 whatever
2.1 Display tutorial
2.2 Change tutorial_on to false/0 whatever
2.3 Store the result in your configuration
Continue using the app
By doing so the first time your app launches the flag responsible for displaying the tutorial will be toggled and afterwards every time you start the app the toggle flag will be read leading to omitting the tutorial.
Personally I would suggest that you an option similar to Don't show tutorial anymore along with a description how to re-enable it (by triggering some action in that app's menu etc.). This has two major benefits:
Improved user experience - users like to have control (especially over trivial matters such as showing or hiding a tutorial). Whenever you take the control away from them, they get pissed off.
Enable your user to re-learn forgotten things - a general rule of thumb is to create apps that should not burden the user with a lot of stuff to remember. That is why things should be self-explanatory. However sometimes you may want to do that nonetheless. By adding the possibility that the user re-launches (by simply resetting the tutorial_on flag and repeating the steps from above) the tutorial allows just that - refreshing a user's memory.
I'm trying the tutorial located here
I have compiled sample code for openCV without issues - so I'm sure I have all the necessary things installed for opencv. I've added the opencv library to my project and I'm compiling with java 1.6 (java 7 doesn't work with opencv4android right now AFAIK). I added the opencv library as a resource as well.
However, the sample code doesn't make sense to me once it gets to step 5 under Hello OpenCV example.
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mView = new HelloOpenCVView(this);
setContentView (mView);
}
Is the code I'm talking about, I immediately get the error "mView cannot be resolved to a variable". mview is consistently used without declaration throughout the code -- is it from another file I'm supposed to be importing? Any ideas? Thanks
B
The "m" in mView indicates that it is a member variable. It's a language naming convention used in most Android apps (you can read more about it here if you feel so inclined). So just add the following inside MyActivity:
public class MyActivity extends Activity implements HelperCallbackInterface
{
private HelloOpenCVView mView;
... // rest of class
}
That should resolve your mView cannot be resolved to a variable error, which is just a scoping issue.
On that page it says to refer to the 15-puzzle sample for more details. I suggest taking a look at it here.
I agree it is a little confusing. Since OpenCV is open source, feel free to send them a GitHub pull request with an amendment to this part of the documentation.
I have one class called Budget.java, within that i start Keypad.java. This was all working fine up until recently when i added a bunch of code to Keypad.java (The added code was to update a row in my SQLite database on the press of a button, all the unrelated methods were working until i tried to implement this). Now using breakpoints i think i've figured out that i get the error message as soon as i try to open the Keypad activity and i don't have a clue what could be the problem.
Maybe it's my misunderstanding of the sqlite open helper? Or perhaps its because i'm using StartActivityForResult?
Any suggestions would be very appreciated! I can upload the logcat if you think that would help.
I uploaded the two little classes to pastebin, you might find it easier to read?
Budget.java ( look for ListItemCommonIntent )
keypad.java
In your Keypad.java, you have the following outside the onCreate:
EditText userAmount=(EditText)this.findViewById(R.id.cost_input);
This wont work because you have to use the setContentView to reference the layout where you want to find the view. And when it initializes userAmount, the object is not available yet (so this is null) .
Try this:
private EditText userAmount;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.keypad);
userAmount=(EditText)findViewById(R.id.cost_input);
MySpinner();
Main();
}
I want to add an entire medical dictionary to my android phone (Moto Droid). I would like to be able to send text messages and have the medical words be in the predictable text.
I've been trying to write a small app that would accomplish this, but everything I try the app crashes on startup. I've never written an app for a mobile platform so that is a first for me. Here is what is not working properly.
public class WordAdd extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
UserDictionary.Words.addWord( this , "newMedicalWord", 1, UserDictionary.Words.LOCALE_TYPE_CURRENT);
}
}
It seems so simple to do, yet I am so stuck. Thanks for any help you can provide.
EDIT: I should mention that I am getting this error for Android 2.1 in the AVD (virtual device).
EDIT 2: User Dictionary is found in the Android API. addWord is a static method. I don't declare UserDictionary because I just use the one static method. It's been ages since I developed anything in Java and this is my first attempt at any mobile development, so I don't know if I am doing something wrong.
Add this to your app's AndroidManifest.xml file outside of the <application> element:
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY"></uses-permission>
Try setting a breakpoint at the start of your activity and stepping through the code with the debugger. This should help you isolate whether that call is really what is causing the crash, and what the underlying exception is.
mm mm where UserDictionary is defined? maybe you should just
UserDictionary = new UserDictionaryType();
UserDictionary.Words = new WordsType();
OR define in the class just under the class declaration the fallowing :
static UserDictionaryType UserDictionary;
if that's the case it's obvious why your app crashed ... (do it on kernel mode and "Houston we got a problem" you cant access pointer that you didnt allocated memory for even in java which is managed code... )
but again I am not familiar with your code show us where it defined and I would try to help you more ...
EDIT1: even if UserDictionary exists in the API you didn't declare on one...
you should declare somewhwere static UserDictionary ud = new UserDictionary();