質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
ウィジェット

ウィジェットとはユーザインタフェイスの要素(GUI widget)であるか、もしくは、独立した比較的サイズの小さいソフトウェアアプリケーション(desktop widget)のことを指します。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

1回答

3196閲覧

AppWidgetが突然動かなくなりました。

sanniichikei

総合スコア12

ウィジェット

ウィジェットとはユーザインタフェイスの要素(GUI widget)であるか、もしくは、独立した比較的サイズの小さいソフトウェアアプリケーション(desktop widget)のことを指します。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2016/06/10 07:33

###前提・実現したいこと
AppWidgetの開発をしている開発初心者です。
仕様は以下の通りです。
・ImageBottun_WorldMapをクリックするとClickWorldMapアクティビティ(今は空の画面を表示するだけ)に遷移する。
・現在の月日時分を表示する

###発生している問題・エラーメッセージ

今日の昼頃までは順調に進んでいたのですが、
ある時突然実機でRunしても時刻が更新されなくなり、
画面遷移もできなくなりました。

ウィジェット自体は表示されます。

###該当のソースコード
マニフェストファイル

xml

1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.example.vmt_038.widgettest6" 4 android:versionCode="1" 5 android:versionName="1.0"> 6 7 <uses-sdk 8 android:minSdkVersion="17" 9 android:targetSdkVersion="23" /> 10 11 <application 12 android:allowBackup="true" 13 android:icon="@mipmap/ic_launcher" 14 android:label="@string/app_name"> 15 16 <android:users-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 17 <android:users-permission android:name="android.permission.READ_PHONE_STATE" /> 18 <android:users-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 19 20 <receiver android:name=".MainActivity"> 21 <intent-filter> 22 <!--<action android:name="android.intent.action.MAIN" />--> 23 <!--<category android:name="android.intent.category.LAUNCHER" />--> 24 <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 25 <action android:name="com.example.(略).widgettest6.CLICK" /> 26 </intent-filter> 27 28 <meta-data 29 android:name="android.appwidget.provider" 30 android:resource="@xml/widget_info" /> 31 </receiver> 32 <service android:name=".UpdateWidgetService"> 33 <intent-filter> 34 <action android:name="com.example.(略).widgettest6.CLICK" /> 35 </intent-filter> 36 </service> 37 38 <receiver android:name=".ReceivedActivity" android:process=":remote" /> 39 40 <activity 41 android:name=".ClickWorldMap"> 42 </activity> 43 44 </application> 45 46</manifest>

MainActivity

java

1import android.appwidget.AppWidgetManager; 2import android.appwidget.AppWidgetProvider; 3import android.content.Context; 4import android.content.Intent; 5 6//ウィジェット実行に必要なクラスを継承したMainActivityクラスを生成する 7public class MainActivity extends AppWidgetProvider { 8 9 10 //AppWidgetProviderにあるonUpdateを、このクラスが実行されている場合のみ下記に書き換える 11 @Override 12 //ウィジェットが更新されたときに呼び出されるメソッド 13 public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 14 15 //onUpdateをスーパークラスに設定 16 super.onUpdate(context, appWidgetManager, appWidgetIds); 17 18// Toast.makeText(context, "表示", Toast.LENGTH_SHORT).show(); 19 //UpdateWidgetServiceへアクティビティを移行するためのインテントを作成 20 Intent intent = new Intent(context.getApplicationContext(), UpdateWidgetService.class); 21 //intentにデータを追加する 22 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds); 23 //アクティビティ移行開始 24 context.startService(intent); 25 } 26 27 @Override 28 public void onReceive(Context ctx, Intent intent) { 29 super.onReceive(ctx, intent); 30 } 31 32 33}

UpdateWidgetService

java

1import android.app.PendingIntent; 2import android.app.Service; 3import android.appwidget.AppWidgetManager; 4import android.content.ComponentName; 5import android.content.Intent; 6import android.os.IBinder; 7import android.widget.RemoteViews; 8import android.widget.Toast; 9 10import java.util.Calendar; 11import java.util.Locale; 12 13/** 14 * Created by VMT-038 on 2016/06/08. 15 */ 16//サービスクラス(ウィジェットをバックグラウンドで実行するクラス)を継承したUpdateWidgetServiceクラスを作成する 17public class UpdateWidgetService extends Service { 18// @SuppressWarnings("deprecation") 19 20 private final String filter = "com.example.(略).widgettest6.CLICK"; 21 22 RemoteViews remoteViews; 23 24 /*---------*/ 25 /* OnStart */ 26 /*---------*/ 27 //ServiceにあるonStartCommandを、このクラスが実行されている場合のみ下記に書き換える 28 @Override 29 //Serviceが実行されると呼び出されるメソッド 30 public int onStartCommand(Intent intent, int flags, int startId) { 31 //onStartCommandをスーパークラスに設定 32 super.onStartCommand(intent, flags, startId); 33 //クラス起動トースト表示 34 Toast.makeText(this, "起動", Toast.LENGTH_SHORT).show(); 35 36 //ウィジェットを表示する 37 remoteViews = new RemoteViews(getPackageName(), R.layout.activity_main); 38 //世界地図クリック時のイベント 39 ClickImageButtonWorldMap(); 40 //反転フラップ部分更新 41 SplitFlapDisplay(); 42 //ウィジェット更新 43 UpdateAppWidget(); 44 //リターン値が必要だがなんでもいいらしい 45 return flags; 46 } 47 48 public void SplitFlapDisplay() { 49 //カレンダーメソッド起動トースト表示 50 Toast.makeText(this, "カレンダー", Toast.LENGTH_SHORT).show(); 51 //カレンダーの値を取得 52 Calendar calendar = Calendar.getInstance(Locale.getDefault()); 53 //int型に端末の現在時間の月を設定(toString使用不可) 54 int month = calendar.get(Calendar.MONTH); 55 //int型に端末の現在時間の日を設定(toString使用不可) 56 int date = calendar.get(Calendar.DATE); 57 //int型に端末の現在時間の時間を設定(toString使用不可) 58 int hour = calendar.get(Calendar.HOUR_OF_DAY); 59 //int型に端末の現在時間の分を設定(toString使用不可) 60 int minute = calendar.get(Calendar.MINUTE); 61 62 //月を英語省略形に変換 63 String strmonth = month(month); 64 65 //時間を表示(""+でint型をString型にキャストする) 66 remoteViews.setTextViewText(R.id.textView_1stDepMonth, strmonth); 67 //時間を表示(""+でint型をString型にキャストする) 68 remoteViews.setTextViewText(R.id.textView_1stDepDate, "" + date); 69 //時間を表示(""+でint型をString型にキャストする) 70 remoteViews.setTextViewText(R.id.textView_1stDepHour, "" + hour); 71 //時間を表示(""+でint型をString型にキャストする) 72 remoteViews.setTextViewText(R.id.textView_1stDepMinute, "" + minute); 73 } 74 75 public void UpdateAppWidget() { 76 //更新メソッド起動トースト表示 77 Toast.makeText(this, "更新", Toast.LENGTH_SHORT).show(); 78 //更新するウィジェットを指定 79 ComponentName thisWidget = new ComponentName(this, MainActivity.class); 80 //? 81 AppWidgetManager manager = AppWidgetManager.getInstance(this); 82 // AppWidgetの画面更新 83 manager.updateAppWidget(thisWidget, remoteViews); 84 } 85 86 public void ClickImageButtonWorldMap() { 87 //ボタンタップメソッド起動トースト表示 88 Toast.makeText(this, "タップ", Toast.LENGTH_SHORT).show(); 89 //画面遷移のためのインテント作成(ウィジェットは通常のIntentは使用不可) 90 Intent buttonIntent = new Intent(this, ClickWorldMap.class); 91 //ボタンが押された時に、ボタンが押されたことを告知する 92 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, buttonIntent, 0); 93 //ボタンクリックによりインテント発行をする設定 94 remoteViews.setOnClickPendingIntent(R.id.ImageButton_WorldMap, pendingIntent); 95 } 96 97 String month(int month) { 98 String strmonth = "メンテナンス中"; 99 switch (month) { 100 case 0: 101 strmonth = "Jan."; 102 break; 103 case 1: 104 strmonth = "Feb."; 105 break; 106 case 2: 107 strmonth = "Mar."; 108 break; 109 case 3: 110 strmonth = "Apr."; 111 break; 112 case 4: 113 strmonth = "May"; 114 break; 115 case 5: 116 strmonth = "Jun."; 117 break; 118 case 6: 119 strmonth = "Jul."; 120 break; 121 case 7: 122 strmonth = "Aug."; 123 break; 124 case 8: 125 strmonth = "Sep."; 126 break; 127 case 9: 128 strmonth = "Oct."; 129 break; 130 case 10: 131 strmonth = "Nov."; 132 break; 133 case 11: 134 strmonth = "Dec."; 135 break; 136 } 137 return strmonth; 138 } 139 140 141 @Override 142 public IBinder onBind(Intent intent) { 143 return null; 144 } 145} 146

###試したこと
不覚にもトラブルが起きた時に保存していなかったため、うまく動いていた時の状態に戻ることができませんでした。

遷移・表示更新ができていたときから、デバッグしても

Could not identify launch activity: Default Activity not found
Error while Launching activity

というエラーが出ていますが、原因がわからず、
とりあえずウィジェットはインストールできていたので開発を進めています。

トーストを作成してもどこのトーストも出現しないので、マニフェストファイルの異常と考えています。

###補足情報(言語/FW/ツール等のバージョンなど)
AndroidStudio2.1で開発中

よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

すみません、解決しました。

Logcatというツールを同僚に教えてもらい(超初歩的で申し訳ありません)、確認したところ、
process is bad というエラーが出ていたので検索してみました。

原因は不明とのことでしたが、実機の再起動により解決できるという方がいたため、実機を再起動したところ、無事実行できました。

デバッグ用のUSBケーブルの接触が悪いことが原因の一つかもしれません。

投稿2016/06/10 08:14

sanniichikei

総合スコア12

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問