0

Hi I am making Android application and I want to make a widget for it. The concept of application is that it gets stt(speech-to-text) string from 'Voicemain_Activity' and put string to created field in 'AddActivity'.And in 'AddActivity' there are a button to call 'Voicemain_Activity'. I was trying to make it to start 'Voicemain_Activity'. So I made widget codes like this. public class MyAppWidget extends AppWidgetProvider {

static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                            int appWidgetId) {
    //CharSequence widgetText = context.getString(R.string.appwidget_text);
    // Construct the RemoteViews object
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_app_widget);
    // views.setTextViewText(R.id.appwidget_text, widgetText);
    Intent intent=new Intent(context, AddActivity.class);
    PendingIntent pe=PendingIntent.getActivity(context, 0, intent, 0);
    views.setOnClickPendingIntent(R.id.imageButton_voice, pe);
    // Instruct the widget manager to update the widget
    appWidgetManager.updateAppWidget(appWidgetId, views);

}

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    super.onUpdate(context,appWidgetManager,appWidgetIds);
    // There may be multiple widgets active, so update all of them
    for (int appWidgetId : appWidgetIds) {
        updateAppWidget(context, appWidgetManager, appWidgetId);
    }
}

@Override
public void onEnabled(Context context) {
    // Enter relevant functionality for when the first widget is created
}

@Override
public void onDisabled(Context context) {
    // Enter relevant functionality for when the last widget is disabled
}

}

the 'AddActivity' that makes to get 'Voicemain_Activity' looks like this.

@Override
public void onClick(View v) {
    int view = v.getId();

    if(view == R.id.Bacode){
        finish();
    }
    else if(view == R.id.Voice){
        startActivityForResult(new Intent(this, VoiceMain_Activity.class), MY_UI);
    }
}

But this code made the widget to just show me the 'Voicemain_Activity' screen and didn't get the string nor put it to 'AddActivity'. How can I make it to work?

  • The question is a little confusing...The problem is that AddActivity is starting Vociemain_Activity, but not getting the result back? But the provided code is mainly showing methods from the widget framework? Does the VoiceMain_Activity call setResult and does AddActivity implement onActivityResult? Can you please show that code. – Elletlar May 07 '18 at 13:04
  • Also, this may help: [How to manage startActivityForResult on Android](https://stackoverflow.com/questions/10407159/how-to-manage-startactivityforresult-on-android) – Elletlar May 07 '18 at 13:09

0 Answers0